Re: [vdagent-win PATCH] file-xfer: handle_start: use snprintf instead of sprintf_s

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> 
> When building with older mingw, sprintf_s does not
> always work as expected, but snprintf does.
> 
> Also it's more consistent in the file.
> 
> Note that when building with VS, snprintf becomes sprintf_s
> 

I think this could be a bug, from documentation:

"If the buffer is too small for the formatted text, including the terminating null, then the buffer is set to an empty string by placing a null character at buffer[0], and the invalid parameter handler is invoked"

which is different from snprintf behaviour, _snprintf is probably what do we want.

> Related: rhbz#1410181
> 
> Signed-off-by: Uri Lublin <uril@xxxxxxxxxx>
> ---
>  vdagent/file_xfer.cpp | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/vdagent/file_xfer.cpp b/vdagent/file_xfer.cpp
> index ada3b47..c456bbe 100644
> --- a/vdagent/file_xfer.cpp
> +++ b/vdagent/file_xfer.cpp
> @@ -113,7 +113,7 @@ void FileXfer::handle_start(VDAgentFileXferStartMessage*
> start,
>          if (attempt == 0) {
>              strcpy(dest_filename, file_name);
>          } else {
> -            sprintf_s(dest_filename, SPICE_N_ELEMENTS(dest_filename),
> +            snprintf(dest_filename, sizeof(dest_filename),
>                        "%.*s (%d)%s", int(extension - file_name), file_name,
>                        attempt, extension);
>          }
>          if ((MultiByteToWideChar(CP_UTF8, 0, dest_filename, -1, file_path +
>          wlen, MAX_PATH - wlen)) == 0) {

Frediano
_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/spice-devel




[Index of Archives]     [Linux Virtualization]     [Linux Virtualization]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]