[PATCH:libXau 1/2] Clean up some clang warnings about sign conversion
Peter Hutterer
peter.hutterer at who-t.net
Mon Dec 17 14:52:43 PST 2012
On Sun, Dec 16, 2012 at 03:53:45PM -0800, Alan Coopersmith wrote:
> fread & fwrite are defined as taking size_t arguments (an unsigned type),
> so stop casting their arguments to a signed int just to confuse things.
>
> Fixes warnings:
>
> AuFileName.c:69:59: warning: implicit conversion loses integer precision: 'unsigned long' to 'int' [-Wshorten-64-to-32]
> size = strlen (name) + strlen(&slashDotXauthority[1]) + 2;
> ~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
>
> AuRead.c:58:44: warning: implicit conversion changes signedness: 'int' to 'size_t' (aka 'unsigned long') [-Wsign-conversion]
> if (fread (data, (int) sizeof (char), (int) len, file) != len) {
> ~~~~~ ^~~~~~~~~
>
> AuWrite.c:49:46: warning: implicit conversion changes signedness: 'int' to 'size_t' (aka 'unsigned long') [-Wsign-conversion]
> if (fwrite (string, (int) sizeof (char), (int) count, file) != count)
> ~~~~~~ ^~~~~~~~~~~
>
> Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
for both
Cheers,
Peter
> ---
> AuFileName.c | 6 +++---
> AuRead.c | 4 ++--
> AuWrite.c | 4 ++--
> 3 files changed, 7 insertions(+), 7 deletions(-)
>
> diff --git a/AuFileName.c b/AuFileName.c
> index bc7b177..473fad1 100644
> --- a/AuFileName.c
> +++ b/AuFileName.c
> @@ -45,12 +45,12 @@ XauFileName (void)
> {
> const char *slashDotXauthority = "/.Xauthority";
> char *name;
> - static int bsize;
> + static size_t bsize;
> static int atexit_registered = 0;
> #ifdef WIN32
> char dir[128];
> #endif
> - int size;
> + size_t size;
>
> if ((name = getenv ("XAUTHORITY")))
> return name;
> @@ -70,7 +70,7 @@ XauFileName (void)
> if (size > bsize) {
> if (buf)
> free (buf);
> - buf = malloc ((unsigned) size);
> + buf = malloc (size);
> if (!buf)
> return NULL;
>
> diff --git a/AuRead.c b/AuRead.c
> index 3c59632..5d41f03 100644
> --- a/AuRead.c
> +++ b/AuRead.c
> @@ -35,7 +35,7 @@ read_short (unsigned short *shortp, FILE *file)
> {
> unsigned char file_short[2];
>
> - if (fread ((char *) file_short, (int) sizeof (file_short), 1, file) != 1)
> + if (fread ((char *) file_short, sizeof (file_short), 1, file) != 1)
> return 0;
> *shortp = file_short[0] * 256 + file_short[1];
> return 1;
> @@ -55,7 +55,7 @@ read_counted_string (unsigned short *countp, char **stringp, FILE *file)
> data = malloc ((unsigned) len);
> if (!data)
> return 0;
> - if (fread (data, (int) sizeof (char), (int) len, file) != len) {
> + if (fread (data, sizeof (char), len, file) != len) {
> bzero (data, len);
> free (data);
> return 0;
> diff --git a/AuWrite.c b/AuWrite.c
> index 0924f8d..1eb38a3 100644
> --- a/AuWrite.c
> +++ b/AuWrite.c
> @@ -36,7 +36,7 @@ write_short (unsigned short s, FILE *file)
>
> file_short[0] = (s & (unsigned)0xff00) >> 8;
> file_short[1] = s & 0xff;
> - if (fwrite ((char *) file_short, (int) sizeof (file_short), 1, file) != 1)
> + if (fwrite ((char *) file_short, sizeof (file_short), 1, file) != 1)
> return 0;
> return 1;
> }
> @@ -46,7 +46,7 @@ write_counted_string (unsigned short count, char *string, FILE *file)
> {
> if (write_short (count, file) == 0)
> return 0;
> - if (fwrite (string, (int) sizeof (char), (int) count, file) != count)
> + if (fwrite (string, sizeof (char), count, file) != count)
> return 0;
> return 1;
> }
> --
> 1.7.9.2
>
> _______________________________________________
> xorg-devel at lists.x.org: X.Org development
> Archives: http://lists.x.org/archives/xorg-devel
> Info: http://lists.x.org/mailman/listinfo/xorg-devel
>
More information about the xorg-devel
mailing list