Skip to content

Commit

Permalink
std.cfg: Added 'indirect' flag for destination argument of 'mbstrtowc…
Browse files Browse the repository at this point in the history
…' function.
  • Loading branch information
orbitcowboy committed Nov 13, 2019
1 parent 7841430 commit 177eed1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
4 changes: 3 additions & 1 deletion cfg/std.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -2362,7 +2362,9 @@
<returnValue type="size_t"/>
<noreturn>false</noreturn>
<leak-ignore/>
<arg nr="1" direction="out"/>
<arg nr="1" direction="out">
<not-uninit indirect="1"/>
</arg>
<arg nr="2" direction="in">
<not-null/>
<not-uninit/>
Expand Down
13 changes: 11 additions & 2 deletions test/cfg/std.c
Original file line number Diff line number Diff line change
Expand Up @@ -1651,14 +1651,23 @@ void uninitvar_mbstowcs(void)
(void)mbstowcs(ws,s,n);
}

void uninitvar_mbsrtowcs(void)
void uninitvar_mbsrtowcs(wchar_t* d, const char** s, size_t m, mbstate_t *p)
{
wchar_t* dest;
const char* src;
size_t max;
mbstate_t* ps;
// cppcheck-suppress uninitvar
(void)mbsrtowcs(dest,&src,max,ps);
(void)mbsrtowcs(dest,s,m,p);
// cppcheck-suppress uninitvar
(void)mbsrtowcs(dest,&src,m,p);

This comment has been minimized.

Copy link
@versat

versat Nov 13, 2019

Collaborator

Since dest is uninitialized, Cppcheck will issue a warning for the first argument. So it does not make a difference whether &src is initialized or not. IMHO it would be better to use d instead of dest for this and the following function calls, so we are sure that the other arguments are verified. What do you think?

This comment has been minimized.

Copy link
@orbitcowboy

orbitcowboy Nov 13, 2019

Author Collaborator

Thank you for pushing me into the right direction ;-) Changes have been addressed with aa5c42f

// cppcheck-suppress uninitvar
(void)mbsrtowcs(dest,s,max,p);
// cppcheck-suppress uninitvar
(void)mbsrtowcs(dest,s,m,ps);

// No warning is expected
(void)mbsrtowcs(d,s,m,p);
}

void uninitvar_wctob(void)
Expand Down

0 comments on commit 177eed1

Please sign in to comment.