On 03/30/12 20:49, Eric Blake wrote: > Laszlo Ersek pointed out that in trying to convert a long to an > unsigned int, we used: > > long long_val = ...; > if ((unsigned int)long_val == long_val) > > According to C99 integer promotion rules, the if statement is > equivalent to: > > (unsigned long)(unsigned int)long_val == (unsigned long)long_val > > since you get an unsigned comparison if at least one side is > unsigned, using the largest rank of the two sides; but on 32-bit > platforms, where unsigned long and unsigned int are the same size, > this comparison is always true and ends up converting negative > long_val into posigive unsigned int values, rather than rejecting > the negative value as we had originally intended (python longs > are unbounded size, and we don't want to do silent modulo > arithmetic when converting to C code). > > Fix this by using direct comparisons, rather than casting. > > * python/typewrappers.c (libvirt_intUnwrap, libvirt_uintUnwrap) > (libvirt_ulongUnwrap, libvirt_ulonglongUnwrap): Fix conversion > checks. I know I'm late but ACK Thanks, Laszlo -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list