[Piglit] [PATCH 6/7] tests/util: Define snprintf as _snprintf on MSVC.

Jose Fonseca jfonseca at vmware.com
Fri Nov 7 10:33:07 PST 2014


sprintf_s prototype matches _snprintf, but the meaning of size parameter seems different: "sizeof(buf)" in sprintf_s, while being "sizeof(bug) - strlen(buf)" for snprintf.

Arguably the *_s functions seem easier to use than standard C ones, but for code that expects snprintf's semantics it might cause wrong results.

Jose

________________________________________
From: Emil Velikov <emil.l.velikov at gmail.com>
Sent: 07 November 2014 17:55
To: Jose Fonseca; piglit at lists.freedesktop.org
Cc: emil.l.velikov at gmail.com
Subject: Re: [Piglit] [PATCH 6/7] tests/util: Define snprintf as _snprintf on MSVC.

On 07/11/14 14:21, jfonseca at vmware.com wrote:
> From: José Fonseca <jfonseca at vmware.com>
>
> As the semantics of sprintf_s's arguments are quite different, so code
> that relies on it might misbehave.
Indeed sprintf_s has an additional argument (buffer_length) which might
cause a bit of an issue.

On a slightly related note, I've used _vsnprintf_s/_vscprintf in waffle
to implement snprintf, yet I'm not sure if it brings anything special
wrt _snprintf.

Any ideas ?

-Emil
> ---
>  tests/util/piglit-util.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tests/util/piglit-util.h b/tests/util/piglit-util.h
> index 0238b7f..84e2066 100755
> --- a/tests/util/piglit-util.h
> +++ b/tests/util/piglit-util.h
> @@ -58,7 +58,7 @@ extern "C" {
>  #define inline __inline
>  #endif
>
> -#define snprintf sprintf_s
> +#define snprintf _snprintf
>
>  #endif /* defined(_MSC_VER) */
>
>


More information about the Piglit mailing list