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

Eric Blake eblake at redhat.com
Tue Mar 30 22:14:49 UTC 2010


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 at redhat.com    +1-801-349-2682
Libvirt virtualization library http://libvirt.org

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


More information about the libvir-list mailing list