[Spice-devel] [PATCH spice-server] Use PRIxPTR constant for string formatting

Christophe Fergeau cfergeau at redhat.com
Tue Sep 18 09:46:28 UTC 2018


Hey,

On Fri, Jun 22, 2018 at 11:28:50AM +0100, Frediano Ziglio wrote:
> These constant are meant to be used in format string for size_t

These constants are actually meant for printing uintptr_t, not size_t,
the former is 32 bits on 32 bits systems, and size_t can be 64 bits
there, see https://github.com/freedesktop/spice/pull/1/commits

%z is actually C99, and is supported by newer VC++ versions
(
https://docs.microsoft.com/en-us/cpp/c-runtime-library/format-specification-syntax-printf-and-wprintf-functions?view=vs-2017
), so I'd tend to switch back to %z, ie revert most of this patch.

Christophe

> types. Use them for portability.
> 
> Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
> ---
>  server/red-record-qxl.c | 4 ++--
>  server/red-replay-qxl.c | 8 ++++----
>  2 files changed, 6 insertions(+), 6 deletions(-)
> 
> diff --git a/server/red-record-qxl.c b/server/red-record-qxl.c
> index 5f6b7aeb..0065fc45 100644
> --- a/server/red-record-qxl.c
> +++ b/server/red-record-qxl.c
> @@ -123,7 +123,7 @@ static void write_binary(FILE *fd, const char *prefix, size_t size, const uint8_
>      }
>  #endif
>  
> -    fprintf(fd, "binary %d %s %zu:", WITH_ZLIB, prefix, size);
> +    fprintf(fd, "binary %d %s %" PRIuPTR ":", WITH_ZLIB, prefix, size);
>  #if WITH_ZLIB
>      zlib_size = zlib_encode(enc, RECORD_ZLIB_DEFAULT_COMPRESSION_LEVEL, size,
>          output, sizeof(output));
> @@ -153,7 +153,7 @@ static size_t red_record_data_chunks_ptr(FILE *fd, const char *prefix,
>          data_size += cur->data_size;
>          count_chunks++;
>      }
> -    fprintf(fd, "data_chunks %d %zu\n", count_chunks, data_size);
> +    fprintf(fd, "data_chunks %d %" PRIuPTR "\n", count_chunks, data_size);
>      memslot_validate_virt(slots, (intptr_t)qxl->data, memslot_id, qxl->data_size, group_id);
>      write_binary(fd, prefix, qxl->data_size, qxl->data);
>  
> diff --git a/server/red-replay-qxl.c b/server/red-replay-qxl.c
> index 18f348a1..a23296cf 100644
> --- a/server/red-replay-qxl.c
> +++ b/server/red-replay-qxl.c
> @@ -266,7 +266,7 @@ static replay_t read_binary(SpiceReplay *replay, const char *prefix, size_t *siz
>              exit(1);
>          }
>          if ((ret = inflate(&strm, Z_NO_FLUSH)) != Z_STREAM_END) {
> -            spice_error("inflate error %d (disc: %ld)", ret, *size - strm.total_out);
> +            spice_error("inflate error %d (disc: %" PRIdPTR ")", ret, *size - strm.total_out);
>              if (ret == Z_DATA_ERROR) {
>                  /* last operation may be wrong. since we do the recording
>                   * in red_worker, when there is a shutdown from the vcpu/io thread
> @@ -296,7 +296,7 @@ static ssize_t red_replay_data_chunks(SpiceReplay *replay, const char *prefix,
>      size_t next_data_size;
>      QXLDataChunk *cur, *next;
>  
> -    replay_fscanf(replay, "data_chunks %u %zu\n", &count_chunks, &data_size);
> +    replay_fscanf(replay, "data_chunks %u %" PRIuPTR "\n", &count_chunks, &data_size);
>      if (replay->error) {
>          return -1;
>      }
> @@ -475,7 +475,7 @@ static QXLImage *red_replay_image(SpiceReplay *replay, uint32_t flags)
>          } else {
>              size = red_replay_data_chunks(replay, "bitmap.data", (uint8_t**)&qxl->bitmap.data, 0);
>              if (size != bitmap_size) {
> -                spice_printerr("bad image, %zu != %zu", size, bitmap_size);
> +                spice_printerr("bad image, %" PRIuPTR " != %" PRIuPTR, size, bitmap_size);
>                  return NULL;
>              }
>          }
> @@ -1137,7 +1137,7 @@ static QXLSurfaceCmd *red_replay_surface_cmd(SpiceReplay *replay)
>          if ((qxl->flags & QXL_SURF_FLAG_KEEP_DATA) != 0) {
>              read_binary(replay, "data", &read_size, (uint8_t**)&qxl->u.surface_create.data, 0);
>              if (read_size != size) {
> -                spice_printerr("mismatch %zu != %zu", size, read_size);
> +                spice_printerr("mismatch %" PRIuPTR " != %" PRIuPTR, size, read_size);
>              }
>          } else {
>              qxl->u.surface_create.data = QXLPHYSICAL_FROM_PTR(replay_malloc(replay, size));
> -- 
> 2.17.1
> 
> _______________________________________________
> Spice-devel mailing list
> Spice-devel at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/spice-devel
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/spice-devel/attachments/20180918/02475099/attachment.sig>


More information about the Spice-devel mailing list