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

Re: [Libguestfs] [PATCH] osinfo: parse also single-digit version numbers



On Mon, Jul 25, 2016 at 06:19:03PM +0200, Pino Toscano wrote:
> Switch to guestfs_int_version_from_x_y_or_x to parse version numbers --
> although, restrict the parsing to what could look like a valid version
> number, to discard quickly version strings like "unknown".
> 
> This makes sure that Debian, Fedora, Mageia, and SLED ISOs have the
> right version number.
> ---
>  src/osinfo.c | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/src/osinfo.c b/src/osinfo.c
> index 0caacfa..907580e 100644
> --- a/src/osinfo.c
> +++ b/src/osinfo.c
> @@ -62,6 +62,7 @@
>  
>  #include "ignore-value.h"
>  #include "glthread/lock.h"
> +#include "c-ctype.h"
>  
>  #include "guestfs.h"
>  #include "guestfs-internal.h"
> @@ -548,9 +549,12 @@ parse_version (guestfs_h *g, xmlNodePtr node, struct osinfo *osinfo)
>    CLEANUP_FREE char *content = NULL;
>  
>    content = (char *) xmlNodeGetContent (node);
> -  if (content) {
> +  /* We parse either "X.Y" or "X" as version strings, so try to parse
> +   * only if the first character is a digit.
> +   */
> +  if (content && c_isdigit (content[0])) {
>      struct version version;
> -    int res = guestfs_int_version_from_x_y (g, &version, content);
> +    int res = guestfs_int_version_from_x_y_or_x (g, &version, content);

This is 'const int' since I pushed some const correctness
changes this morning.

>      if (res < 0)
>        return -1;
>      else if (res > 0) {

ACK.

Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
Fedora Windows cross-compiler. Compile Windows programs, test, and
build Windows installers. Over 100 libraries supported.
http://fedoraproject.org/wiki/MinGW


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