Re: [libvirt] [PATCH 03/10] Refactor major.minor.micro version parsing into a function

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 03/30/2010 10:20 AM, Matthias Bolte wrote:
> +/**
> + * virParseVersionString:
> + * @str: const char pointer to the version string
> + * @version: unsigned long pointer to output the version number
> + *
> + * Parse an unsigned version number from a version string. Expecting
> + * 'major.minor.micro' format, ignoring an optional suffix.
> + *
> + * The major, minor and micro numbers are encoded into a single version number:
> + *
> + *   1000000 * major + 1000 * minor + micro
> + *
> + * Returns the 0 for success, -1 for error.
> + */
> +int
> +virParseVersionString(const char *str, unsigned long *version)
> +{
> +    unsigned int major, minor, micro;
> +    char *tmp = (char *)str;
> +
> +    if (virStrToLong_ui(tmp, &tmp, 10, &major) < 0 || tmp == NULL ||

Another instance (2 times) where the tmp==NULL check is spurious.  But I
didn't see anything else wrong with this patch.

> -            if (sscanf(version, "%ld.%ld.%ld", &major, &minor, &release) != 3) {
> -                xenapiSessionErrorHandler(conn, VIR_ERR_INTERNAL_ERROR, "Couldn't get version info");
> -                xen_string_string_map_free(result);
> -                VIR_FREE(version);
> -                return -1;
> -            }
> -            *hvVer = major * 1000000 + minor * 1000 + release;
> -            VIR_FREE(version);
> +            if (virParseVersionString(version, hvVer) < 0)
> +                xenapiSessionErrorHandler(conn, VIR_ERR_INTERNAL_ERROR,
> +                                          "Couldn't parse version info");

Not introduced by your patch, but should we be translating this error
message?

-- 
Eric Blake   eblake@xxxxxxxxxx    +1-801-349-2682
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]