[libvirt] [PATCH] virdbustest: Don't pass number of arguments as long long

since sizeof(size_t) != sizeof(long long) on 32bit archs. This unbreaks virdbustest which otherwise fails like: (gdb) bt #0 __strlen_sse2_bsf () at ../sysdeps/i386/i686/multiarch/strlen-sse2-bsf.S:50 #1 0x405907d2 in ?? () from /lib/i386-linux-gnu/libdbus-1.so.3 #2 0x4057c140 in ?? () from /lib/i386-linux-gnu/libdbus-1.so.3 #3 0x4057e7ec in dbus_message_iter_append_basic () from /lib/i386-linux-gnu/libdbus-1.so.3 #4 0x400742ec in virDBusMessageIterEncode (args=0xbfd4b8f0 "k\321\004\b.", types=0x804d260 "", rootiter=0xbfd4b844) at util/virdbus.c:560 #5 virDBusMessageEncodeArgs (msg=msg@entry=0x893c278, types=types@entry=0x804d25c "sais", args=args@entry=0xbfd4b8d8 "r\320\004\b\003") at util/virdbus.c:921 #6 0x40075917 in virDBusMessageEncode (msg=0x893c278, types=0x804d25c "sais") at util/virdbus.c:959 #7 0x0804a4a1 in testMessageArray (args=0x0) at virdbustest.c:195 #8 0x0804c404 in virtTestRun (title=title@entry=0x804cfcb "Test message array ", nloops=nloops@entry=1, body=body@entry=0x804a3f0 <testMessageArray>, data=data@entry=0x0) at testutils.c:168 #9 0x08049346 in mymain () at virdbustest.c:384 #10 0x0804cb2e in virtTestMain (argc=argc@entry=1, argv=argv@entry=0xbfd4bb24, func=func@entry=0x80492c0 <mymain>) at testutils.c:764 #11 0x080491af in main (argc=1, argv=0xbfd4bb24) at virdbustest.c:393 --- tests/virdbustest.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/virdbustest.c b/tests/virdbustest.c index e054716..ac57422 100644 --- a/tests/virdbustest.c +++ b/tests/virdbustest.c @@ -195,7 +195,7 @@ static int testMessageArray(const void *args ATTRIBUTE_UNUSED) if (virDBusMessageEncode(msg, "sais", in_str1, - (long long)3, in_int32a, in_int32b, in_int32c, + (size_t)3, in_int32a, in_int32b, in_int32c, in_str2) < 0) { VIR_DEBUG("Failed to encode arguments"); goto cleanup; -- 1.8.3.2

On 07/24/2013 03:29 PM, Guido Günther wrote:
since sizeof(size_t) != sizeof(long long) on 32bit archs.
This unbreaks virdbustest which otherwise fails like:
+++ b/tests/virdbustest.c @@ -195,7 +195,7 @@ static int testMessageArray(const void *args ATTRIBUTE_UNUSED) if (virDBusMessageEncode(msg, "sais", in_str1, - (long long)3, in_int32a, in_int32b, in_int32c, + (size_t)3, in_int32a, in_int32b, in_int32c,
This fix looks correct, but it's annoying that we have to cast the 'a' length argument in every caller. I'm wondering if a better fix would be to virDBusMessageEncode to take an 'int' instead of a 'size_t' arg for "a" length; even though that is technically an arbitrary limitation on 64-bit platforms, I seriously doubt anyone plans to use dBus to send more than 2G of objects. -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

On Wed, Jul 24, 2013 at 03:41:17PM -0600, Eric Blake wrote:
On 07/24/2013 03:29 PM, Guido Günther wrote:
since sizeof(size_t) != sizeof(long long) on 32bit archs.
This unbreaks virdbustest which otherwise fails like:
+++ b/tests/virdbustest.c @@ -195,7 +195,7 @@ static int testMessageArray(const void *args ATTRIBUTE_UNUSED) if (virDBusMessageEncode(msg, "sais", in_str1, - (long long)3, in_int32a, in_int32b, in_int32c, + (size_t)3, in_int32a, in_int32b, in_int32c,
This fix looks correct, but it's annoying that we have to cast the 'a' length argument in every caller. I'm wondering if a better fix would be to virDBusMessageEncode to take an 'int' instead of a 'size_t' arg for "a" length; even though that is technically an arbitrary limitation on 64-bit platforms, I seriously doubt anyone plans to use dBus to send more than 2G of objects.
I agree with your point, but for the sake of fixing this in 1.1.1 maybe that small patch is the right approach, then fix the internal APIs after the freeze. Makes sense ? Daniel -- Daniel Veillard | Open Source and Standards, Red Hat veillard@redhat.com | libxml Gnome XML XSLT toolkit http://xmlsoft.org/ http://veillard.com/ | virtualization library http://libvirt.org/

Hi Eric, On Wed, Jul 24, 2013 at 03:41:17PM -0600, Eric Blake wrote:
On 07/24/2013 03:29 PM, Guido Günther wrote:
since sizeof(size_t) != sizeof(long long) on 32bit archs.
This unbreaks virdbustest which otherwise fails like:
+++ b/tests/virdbustest.c @@ -195,7 +195,7 @@ static int testMessageArray(const void *args ATTRIBUTE_UNUSED) if (virDBusMessageEncode(msg, "sais", in_str1, - (long long)3, in_int32a, in_int32b, in_int32c, + (size_t)3, in_int32a, in_int32b, in_int32c,
This fix looks correct, but it's annoying that we have to cast the 'a' length argument in every caller. I'm wondering if a better fix would be to virDBusMessageEncode to take an 'int' instead of a 'size_t' arg for "a" length; even though that is technically an arbitrary limitation on 64-bit platforms, I seriously doubt anyone plans to use dBus to send more than 2G of objects.
I'm not sure we need to change anything. Removing the (long long) is enough to make the tests pass on 32bit as well as 64bit x86. It's just that we must not pass in an 8byte type on i386. I just left left the cast to size_t in since I suspected some (yet to me unclear) intention behind an explicit cast. Cheers, -- Guido
-- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

On Wed, Jul 24, 2013 at 03:41:17PM -0600, Eric Blake wrote:
On 07/24/2013 03:29 PM, Guido Günther wrote:
since sizeof(size_t) != sizeof(long long) on 32bit archs.
This unbreaks virdbustest which otherwise fails like:
+++ b/tests/virdbustest.c @@ -195,7 +195,7 @@ static int testMessageArray(const void *args ATTRIBUTE_UNUSED) if (virDBusMessageEncode(msg, "sais", in_str1, - (long long)3, in_int32a, in_int32b, in_int32c, + (size_t)3, in_int32a, in_int32b, in_int32c,
This fix looks correct, but it's annoying that we have to cast the 'a' length argument in every caller. I'm wondering if a better fix would be to virDBusMessageEncode to take an 'int' instead of a 'size_t' arg for "a" length; even though that is technically an arbitrary limitation on 64-bit platforms, I seriously doubt anyone plans to use dBus to send more than 2G of objects.
The code requires an int already narray = va_arg(args, int); so both the (long long) and (size_t) casts are bogus. We can just remove the cast completely. Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

since sizeof(int) != sizeof(long long) on 32bit archs. This unbreaks virdbustest which otherwise fails like: (gdb) bt #0 __strlen_sse2_bsf () at ../sysdeps/i386/i686/multiarch/strlen-sse2-bsf.S:50 #1 0x405907d2 in ?? () from /lib/i386-linux-gnu/libdbus-1.so.3 #2 0x4057c140 in ?? () from /lib/i386-linux-gnu/libdbus-1.so.3 #3 0x4057e7ec in dbus_message_iter_append_basic () from /lib/i386-linux-gnu/libdbus-1.so.3 #4 0x400742ec in virDBusMessageIterEncode (args=0xbfd4b8f0 "k\321\004\b.", types=0x804d260 "", rootiter=0xbfd4b844) at util/virdbus.c:560 #5 virDBusMessageEncodeArgs (msg=msg@entry=0x893c278, types=types@entry=0x804d25c "sais", args=args@entry=0xbfd4b8d8 "r\320\004\b\003") at util/virdbus.c:921 #6 0x40075917 in virDBusMessageEncode (msg=0x893c278, types=0x804d25c "sais") at util/virdbus.c:959 #7 0x0804a4a1 in testMessageArray (args=0x0) at virdbustest.c:195 #8 0x0804c404 in virtTestRun (title=title@entry=0x804cfcb "Test message array ", nloops=nloops@entry=1, body=body@entry=0x804a3f0 <testMessageArray>, data=data@entry=0x0) at testutils.c:168 #9 0x08049346 in mymain () at virdbustest.c:384 #10 0x0804cb2e in virtTestMain (argc=argc@entry=1, argv=argv@entry=0xbfd4bb24, func=func@entry=0x80492c0 <mymain>) at testutils.c:764 #11 0x080491af in main (argc=1, argv=0xbfd4bb24) at virdbustest.c:393 --- tests/virdbustest.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/virdbustest.c b/tests/virdbustest.c index e054716..fb241ee 100644 --- a/tests/virdbustest.c +++ b/tests/virdbustest.c @@ -195,7 +195,7 @@ static int testMessageArray(const void *args ATTRIBUTE_UNUSED) if (virDBusMessageEncode(msg, "sais", in_str1, - (long long)3, in_int32a, in_int32b, in_int32c, + 3, in_int32a, in_int32b, in_int32c, in_str2) < 0) { VIR_DEBUG("Failed to encode arguments"); goto cleanup; -- 1.8.3.2

On Thu, Jul 25, 2013 at 01:25:32PM +0200, Guido Günther wrote:
since sizeof(int) != sizeof(long long) on 32bit archs.
This unbreaks virdbustest which otherwise fails like:
(gdb) bt #0 __strlen_sse2_bsf () at ../sysdeps/i386/i686/multiarch/strlen-sse2-bsf.S:50 #1 0x405907d2 in ?? () from /lib/i386-linux-gnu/libdbus-1.so.3 #2 0x4057c140 in ?? () from /lib/i386-linux-gnu/libdbus-1.so.3 #3 0x4057e7ec in dbus_message_iter_append_basic () from /lib/i386-linux-gnu/libdbus-1.so.3 #4 0x400742ec in virDBusMessageIterEncode (args=0xbfd4b8f0 "k\321\004\b.", types=0x804d260 "", rootiter=0xbfd4b844) at util/virdbus.c:560 #5 virDBusMessageEncodeArgs (msg=msg@entry=0x893c278, types=types@entry=0x804d25c "sais", args=args@entry=0xbfd4b8d8 "r\320\004\b\003") at util/virdbus.c:921 #6 0x40075917 in virDBusMessageEncode (msg=0x893c278, types=0x804d25c "sais") at util/virdbus.c:959 #7 0x0804a4a1 in testMessageArray (args=0x0) at virdbustest.c:195 #8 0x0804c404 in virtTestRun (title=title@entry=0x804cfcb "Test message array ", nloops=nloops@entry=1, body=body@entry=0x804a3f0 <testMessageArray>, data=data@entry=0x0) at testutils.c:168 #9 0x08049346 in mymain () at virdbustest.c:384 #10 0x0804cb2e in virtTestMain (argc=argc@entry=1, argv=argv@entry=0xbfd4bb24, func=func@entry=0x80492c0 <mymain>) at testutils.c:764 #11 0x080491af in main (argc=1, argv=0xbfd4bb24) at virdbustest.c:393 --- tests/virdbustest.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tests/virdbustest.c b/tests/virdbustest.c index e054716..fb241ee 100644 --- a/tests/virdbustest.c +++ b/tests/virdbustest.c @@ -195,7 +195,7 @@ static int testMessageArray(const void *args ATTRIBUTE_UNUSED) if (virDBusMessageEncode(msg, "sais", in_str1, - (long long)3, in_int32a, in_int32b, in_int32c, + 3, in_int32a, in_int32b, in_int32c, in_str2) < 0) { VIR_DEBUG("Failed to encode arguments"); goto cleanup;
ACK Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

On 07/25/2013 03:27 AM, Daniel P. Berrange wrote:
This fix looks correct, but it's annoying that we have to cast the 'a' length argument in every caller. I'm wondering if a better fix would be to virDBusMessageEncode to take an 'int' instead of a 'size_t' arg for "a" length; even though that is technically an arbitrary limitation on 64-bit platforms, I seriously doubt anyone plans to use dBus to send more than 2G of objects.
The code requires an int already
narray = va_arg(args, int);
Yay - the underlying implementation is correct.
so both the (long long) and (size_t) casts are bogus. We can just remove the cast completely.
Serves me right for not checking whether the va_arg was using the right type in the first place. Guido's second version that drops the cast completely is correct. -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

On Thu, Jul 25, 2013 at 07:37:48AM -0600, Eric Blake wrote:
On 07/25/2013 03:27 AM, Daniel P. Berrange wrote:
This fix looks correct, but it's annoying that we have to cast the 'a' length argument in every caller. I'm wondering if a better fix would be to virDBusMessageEncode to take an 'int' instead of a 'size_t' arg for "a" length; even though that is technically an arbitrary limitation on 64-bit platforms, I seriously doubt anyone plans to use dBus to send more than 2G of objects.
The code requires an int already
narray = va_arg(args, int);
Yay - the underlying implementation is correct.
so both the (long long) and (size_t) casts are bogus. We can just remove the cast completely.
Serves me right for not checking whether the va_arg was using the right type in the first place. Guido's second version that drops the cast completely is correct.
Same here. I assumed size_t but should have double checked. Pushed now, thanks, -- Guido
-- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
participants (4)
-
Daniel P. Berrange
-
Daniel Veillard
-
Eric Blake
-
Guido Günther