diff mbox

qga/commands-posix.c: Use correct types with g_base64_decode()

Message ID 1428523369-13700-1-git-send-email-peter.maydell@linaro.org
State Rejected
Headers show

Commit Message

Peter Maydell April 8, 2015, 8:02 p.m. UTC
The second argument of g_base64_decode() is a 'gsize *', not a
'size_t *'. Some compilation environments (like building 32-bit PPC
binaries on a PPC64 system) will complain about the mismatch:

  CC    qga/commands-posix.o
qga/commands-posix.c: In function 'qmp_guest_set_user_password':
qga/commands-posix.c:1908:5: error: passing argument 2 of 'g_base64_decode' from incompatible pointer type [-Werror]
In file included from /usr/include/glib-2.0/glib.h:37:0,
                 from qga/commands-posix.c:14:
/usr/include/glib-2.0/glib/gbase64.h:49:9: note: expected ‘gsize *’ but argument is of type ‘size_t *’

(We previously fixed errors of this type in commit 3d1bba20.)

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
 qga/commands-posix.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Peter Maydell April 14, 2015, 1:41 p.m. UTC | #1
On 14 April 2015 at 14:38, Thomas Huth <thuth@redhat.com> wrote:
> Am Wed,  8 Apr 2015 21:02:49 +0100
> schrieb Peter Maydell <peter.maydell@linaro.org>:
>
>> The second argument of g_base64_decode() is a 'gsize *', not a
>> 'size_t *'. Some compilation environments (like building 32-bit PPC
>> binaries on a PPC64 system) will complain about the mismatch:
>>
>>   CC    qga/commands-posix.o
>> qga/commands-posix.c: In function 'qmp_guest_set_user_password':
>> qga/commands-posix.c:1908:5: error: passing argument 2 of 'g_base64_decode' from incompatible pointer type [-Werror]
>> In file included from /usr/include/glib-2.0/glib.h:37:0,
>>                  from qga/commands-posix.c:14:
>> /usr/include/glib-2.0/glib/gbase64.h:49:9: note: expected ‘gsize *’ but argument is of type ‘size_t *’
>>
>> (We previously fixed errors of this type in commit 3d1bba20.)
>>
>> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
>> ---
>>  qga/commands-posix.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/qga/commands-posix.c b/qga/commands-posix.c
>> index ba8de62..9fde348 100644
>> --- a/qga/commands-posix.c
>> +++ b/qga/commands-posix.c
>> @@ -1901,7 +1901,7 @@ void qmp_guest_set_user_password(const char *username,
>>      int status;
>>      int datafd[2] = { -1, -1 };
>>      char *rawpasswddata = NULL;
>> -    size_t rawpasswdlen;
>> +    gsize rawpasswdlen;
>>      char *chpasswddata = NULL;
>>      size_t chpasswdlen;
>>
>
> I've just ran into this issue as well on my x86 laptop when playing
> around with "--extra-cflags=-m32"... so should this be fixed for the
> 2.3 release already? I didn't spot your patch on the master branch
> yet...

No, this is not-for-2.3. I think that the issue here is that
merely adding -m32 isn't sufficient, because pkg-config when
run by configure will end up pointing at a bunch of incorrect
glib includes (for x86-64, not i386). So the actual solution
is to give configure the right pkg-config, and then gsize and
size_t are the same. There's a patch by John Snow for
configure on-list for that.

-- PMM
Peter Maydell April 14, 2015, 1:45 p.m. UTC | #2
On 14 April 2015 at 14:42, Paolo Bonzini <pbonzini@redhat.com> wrote:
>
>
> On 08/04/2015 22:02, Peter Maydell wrote:
>> The second argument of g_base64_decode() is a 'gsize *', not a
>> 'size_t *'. Some compilation environments (like building 32-bit PPC
>> binaries on a PPC64 system) will complain about the mismatch:
>>
>>   CC    qga/commands-posix.o
>> qga/commands-posix.c: In function 'qmp_guest_set_user_password':
>> qga/commands-posix.c:1908:5: error: passing argument 2 of 'g_base64_decode' from incompatible pointer type [-Werror]
>> In file included from /usr/include/glib-2.0/glib.h:37:0,
>>                  from qga/commands-posix.c:14:
>> /usr/include/glib-2.0/glib/gbase64.h:49:9: note: expected ‘gsize *’ but argument is of type ‘size_t *’
>>
>> (We previously fixed errors of this type in commit 3d1bba20.)
>>
>> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
>
> I think this patch is wrong.  Considering what Thomas was doing
> ("playing around with --extra-cflags=-m32" on x86) this looks like
> you're using the 64-bit glib headers while doing a 32-bit compilation.

I sort of agree, but I don't think the patch is wrong as such.
The API of the function we're calling demands a pointer to a
'gsize', so we should do that, not rely implicitly on 'gsize'
and 'size_t' being interchangeable.

(I have no idea why glib sees fit to define its own versions
of the standard types, but given that it does we should get
the interfacing to them right...)

-- PMM
Peter Maydell April 14, 2015, 2:36 p.m. UTC | #3
On 14 April 2015 at 15:29, Paolo Bonzini <pbonzini@redhat.com> wrote:
> If anything, I would add a QEMU_BUILD_BUG_ON(sizeof(gsize) !=
> sizeof(size_t)) to catch the problem, since we've had many experienced
> developers caught unprepared.

...put it in configure, since it's a configuration error?

-- PMM
diff mbox

Patch

diff --git a/qga/commands-posix.c b/qga/commands-posix.c
index ba8de62..9fde348 100644
--- a/qga/commands-posix.c
+++ b/qga/commands-posix.c
@@ -1901,7 +1901,7 @@  void qmp_guest_set_user_password(const char *username,
     int status;
     int datafd[2] = { -1, -1 };
     char *rawpasswddata = NULL;
-    size_t rawpasswdlen;
+    gsize rawpasswdlen;
     char *chpasswddata = NULL;
     size_t chpasswdlen;