[libvirt] [PATCHv2 09/15] xml: use better types for memory values

Eric Blake eblake at redhat.com
Thu Mar 8 00:12:18 UTC 2012


On 03/06/2012 09:34 AM, Peter Krempa wrote:
> On 03/06/2012 01:34 AM, Eric Blake wrote:
>> Using 'unsigned long' for memory values is risky on 32-bit platforms,
>> as a PAE guest can have more than 4GiB memory.  Our API is
>> (unfortunately) locked at 'unsigned long' and a scale of 1024, but
>> the rest of our system should consistently use 64-bit values,
>> especially since the previous patch centralized overflow checking.
>>

>> +++ b/src/xenxs/xen_sxpr.c
>> @@ -1101,9 +1133,15 @@ cleanup:
>>
>>
>>   static
>> -int xenXMConfigSetInt(virConfPtr conf, const char *setting, long l) {
>> +int xenXMConfigSetInt(virConfPtr conf, const char *setting, long long
>> l) {
>>       virConfValuePtr value = NULL;
>>
>> +    if ((long) l != l) {
>> +        XENXS_ERROR(VIR_ERR_INTERNAL_ERROR,
> 
> I suppose the VIR_ERR_INTERNAL_ERROR is intentional.

Yes - the libvirt.c interface takes 'unsigned long', and widening that
to long long should be reversible so we should never hit this error.

> 
>> +                    _("integer overflow in trying to store %lld to %s"),
>> +                    l, setting);
>> +        return -1;
>> +    }
>>       if (VIR_ALLOC(value)<  0) {
>>           virReportOOMError();
>>           return -1;
> 
> ACK,
> 
> Peter
> 

-- 
Eric Blake   eblake at redhat.com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 620 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20120307/4c64a527/attachment-0001.sig>


More information about the libvir-list mailing list