[ovs-dev] [PATCH v2] util: New wrapper function ovs_vsnprintf().

Ben Pfaff blp at nicira.com
Thu Dec 19 23:17:26 UTC 2013


On Thu, Dec 19, 2013 at 03:02:55PM -0800, Saurabh Shah wrote:
> 
> On Thu, Dec 19, 2013 at 11:44:54AM -0800, Saurabh Shah wrote:
> So that vsnprintf on windows has C99 like semantics.
> Signed-off-by: Saurabh Shah <ssaurabh at nicira.com<mailto:ssaurabh at nicira.com>>
> 
> Doesn't snprintf() need the same treatment?  Is there a reason not to
> handle it in the same patch?
> 
> Ah, thanks, I missed this. Someone had defined snprintf to sprintf_s
> and I didn't catch that. If the approach is fine I can update the
> patch with a similar wrapper for snprintf. (I hope I am not missing
> any other print function :))

The approach is OK.

> With this patch applied, if I add a file lib/stdio.h with the
> following contents:
> 
>     #if defined __need_FILE || defined __need___FILE
>     /* Special invocation from within glibc. */
>     #include_next <stdio.h>
>     #elif !defined STDIO_H_WRAPPER
>     #define STDIO_H_WRAPPER 1
>     #include_next <stdio.h>
> 
>     #undef snprintf
>     #define snprintf(...) ((void) snprintf(__VA_ARGS__))
> 
>     #undef vsnprintf
>     #define vsnprintf(...) ((void) vsnprintf(__VA_ARGS__))
> 
>     #endif /* stdio.h wrapper */
> 
> then I get plenty of errors:
> 
>     ../lib/command-line.c: In function 'proctitle_set':
>     ../lib/command-line.c:172:7: error: void value not ignored as it ought to be
>     ../lib/vlandev.c: In function 'vlandev_dummy_add':
>     ../lib/vlandev.c:318:5: error: void value not ignored as it ought to be
>     ../lib/json.c: In function 'json_serialized_length':
>     ../lib/json.c:1743:9: error: void value not ignored as it ought to be
>     ../lib/json.c:1746:9: error: void value not ignored as it ought to be
>     ../lib/match.c: In function 'match_format':
>     ../lib/match.c:924:9: error: void value not ignored as it ought to be
>     ../lib/socket-util.c: In function 'shorten_name_via_proc':
>     ../lib/socket-util.c:377:9: error: void value not ignored as it ought to be
>     ../lib/socket-util.c: In function 'shorten_name_via_symlink':
>     ../lib/socket-util.c:418:13: error: void value not ignored as it ought to be
>     ../lib/socket-util.c:433:13: error: void value not ignored as it ought to be
> 
> I think, this is because the lib/stdio.h you defined wants the
> caller to ignore the return type of snprintf, but they don't. I get
> the same error if I just add lib/stdio.h without any of my
> changes. This change should ideally not affect any non-windows at
> all, other than a function indirection.

My understanding is that the issue with Windows (v)snprintf is its
return value is wrong.  The goal of my change was to automatically
find all the places in the tree where the return value mattered.  That
is, all of the errors above are places where snprintf() needs to get
replaced by some wrapper that returns the correct value.

Thanks,

Ben.



More information about the dev mailing list