Re: [RFA record/replay] cast to avoid compiler warning

Mark Kettenis
2008-10-04T21:53:06Z

> Date: Sat, 04 Oct 2008 11:42:47 -0700
> From: Michael Snyder <msnyder@vmware.com>
>
> Sizeof returns size_t, which is not always the same as int.
> This cast will prevent compiler warnings on some architectures
> (eg. x86_64)

This is wrong! Better cast to unsigned long and print as %lu.

There is a C99 way to do this, but not all systems implement it properly.

> 2008-10-03 Michael Snyder <msnyder@promb-2s-dhcp59.eng.vmware.com>
>
> * linux-record.c (record_linux_system_call): Cast sizeof to int
> in printf calls, avoid compiler warnings on 64 bit hosts.
>
> Index: linux-record.c
> ===================================================================
> RCS file: /cvs/src/src/gdb/Attic/linux-record.c,v
> retrieving revision 1.1.2.4
> diff -u -p -r1.1.2.4 linux-record.c
> --- linux-record.c 7 Sep 2008 01:40:43 -0000 1.1.2.4
> +++ linux-record.c 3 Oct 2008 23:04:20 -0000
> @@ -597,7 +597,7 @@ record_linux_system_call (int num, linux
> {
> fprintf_unfiltered (gdb_stdlog,
> "Record: read memory addr = 0x%s len = %d error.\n",
> - paddr_nz (tmpu32), sizeof (sel));
> + paddr_nz (tmpu32), (int) sizeof (sel));
> return (-1);
> }
> if (record_arch_list_add_mem (sel.inp, tdep->size_fd_set))
> @@ -749,7 +749,7 @@ record_linux_system_call (int num, linux
> {
> fprintf_unfiltered (gdb_stdlog,
> "Record: read memory addr = 0x%s len = %d error.\n",
> - paddr_nz (tmpu32), sizeof (a));
> + paddr_nz (tmpu32), (int) sizeof (a));
> return (-1);
> }
> if (record_arch_list_add_mem (a[1], tdep->size_sockaddr))
> @@ -775,7 +775,7 @@ record_linux_system_call (int num, linux
> {
> fprintf_unfiltered (gdb_stdlog,
> "Record: read memory addr = 0x%s len = %d error.\n",
> - paddr_nz (tmpu32), sizeof (a));
> + paddr_nz (tmpu32), (int) sizeof (a));
> return (-1);
> }
> if (record_arch_list_add_mem (a[3], tdep->size_int))
> @@ -799,7 +799,7 @@ record_linux_system_call (int num, linux
> {
> fprintf_unfiltered (gdb_stdlog,
> "Record: read memory addr = 0x%s len = %d error.\n",
> - paddr_nz (tmpu32), sizeof (a));
> + paddr_nz (tmpu32), (int) sizeof (a));
> return (-1);
> }
> if (a[2])
> @@ -809,7 +809,7 @@ record_linux_system_call (int num, linux
> {
> fprintf_unfiltered (gdb_stdlog,
> "Record: read memory addr = 0x%s len = %d error.\n",
> - paddr_nz (a[2]), sizeof (a[2]));
> + paddr_nz (a[2]), (int) sizeof (a[2]));
> return (-1);
> }
> if (record_arch_list_add_mem (a[1], a[2]))
> @@ -831,7 +831,7 @@ record_linux_system_call (int num, linux
> {
> fprintf_unfiltered (gdb_stdlog,
> "Record: read memory addr = 0x%s len = %d error.\n",
> - paddr_nz (tmpu32), sizeof (a));
> + paddr_nz (tmpu32), (int) sizeof (a));
> return (-1);
> }
> if (a[2])
> @@ -841,7 +841,7 @@ record_linux_system_call (int num, linux
> {
> fprintf_unfiltered (gdb_stdlog,
> "Record: read memory addr = 0x%s len = %d error.\n",
> - paddr_nz (a[2]), sizeof (a[2]));
> + paddr_nz (a[2]), (int) sizeof (a[2]));
> return (-1);
> }
> if (record_arch_list_add_mem (a[1], a[2]))
> @@ -876,7 +876,7 @@ record_linux_system_call (int num, linux
> {
> fprintf_unfiltered (gdb_stdlog,
> "Record: read memory addr = 0x%s len = %d error.\n",
> - paddr_nz (tmpu32), sizeof (a));
> + paddr_nz (tmpu32), (int) sizeof (a));
> return (-1);
> }
> if (a[4])
> @@ -886,7 +886,7 @@ record_linux_system_call (int num, linux
> {
> fprintf_unfiltered (gdb_stdlog,
> "Record: read memory addr = 0x%s len = %d error.\n",
> - paddr_nz (a[4]), sizeof (av));
> + paddr_nz (a[4]), (int) sizeof (av));
> return (-1);
> }
> if (record_arch_list_add_mem (a[3], av))
> @@ -930,7 +930,7 @@ record_linux_system_call (int num, linux
> {
> fprintf_unfiltered (gdb_stdlog,
> "Record: read memory addr = 0x%s len = %d error.\n",
> - paddr_nz (tmpu32), sizeof (a));
> + paddr_nz (tmpu32), (int) sizeof (a));
> return (-1);
> }
> if (record_arch_list_add_mem (a[1], tdep->size_msghdr))
> @@ -944,7 +944,7 @@ record_linux_system_call (int num, linux
> {
> fprintf_unfiltered (gdb_stdlog,
> "Record: read memory addr = 0x%s len = %d error.\n",
> - paddr_nz (a[1]), sizeof (rec));
> + paddr_nz (a[1]), (int) sizeof (rec));
> return (-1);
> }
> if (record_arch_list_add_mem
> @@ -968,7 +968,7 @@ record_linux_system_call (int num, linux
> fprintf_unfiltered (gdb_stdlog,
> "Record: read memory addr = 0x%s len = %d error.\n",
> paddr_nz (rec.msg_iov),
> - sizeof (iov));
> + (int) sizeof (iov));
> return (-1);
> }
> if (record_arch_list_add_mem
> @@ -1336,7 +1336,7 @@ record_linux_system_call (int num, linux
> fprintf_unfiltered (gdb_stdlog,
> "Record: read memory addr = 0x%s len = %d error.\n",
> paddr_nz (vec),
> - sizeof (struct record_iovec));
> + (int) sizeof (struct record_iovec));
> return (-1);
> }
> if (record_arch_list_add_mem (iov.iov_base, iov.iov_len))