[virt-tools-list] [libosinfo] Correct pattern matching logic

Christophe Fergeau cfergeau at redhat.com
Thu Nov 24 09:11:49 UTC 2011


On Thu, Nov 24, 2011 at 04:23:24AM +0200, Zeeshan Ali (Khattak) wrote:
> From: "Zeeshan Ali (Khattak)" <zeeshanak at gnome.org>
> 
> If both pattern and string are NULL, they should match.

Have you met cases where it's needed? In the tests I ran, I'm not getting
NULL strings but strings full of whitespace when some fields are not set in
the iso,

Christophe

> ---
>  osinfo/osinfo_db.c |    5 +++--
>  1 files changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/osinfo/osinfo_db.c b/osinfo/osinfo_db.c
> index 4394dcf..d9ec6e3 100644
> --- a/osinfo/osinfo_db.c
> +++ b/osinfo/osinfo_db.c
> @@ -30,8 +30,9 @@ G_DEFINE_TYPE (OsinfoDb, osinfo_db, G_TYPE_OBJECT);
>  
>  #define OSINFO_DB_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), OSINFO_TYPE_DB, OsinfoDbPrivate))
>  
> -#define match_regex(pattern, str) ((pattern) && (str) && \
> -                                   g_regex_match_simple((pattern), (str), 0, 0))
> +#define match_regex(pattern, str) (((pattern) == NULL && (str) == NULL) || \
> +                                   ((pattern) != NULL && (str) != NULL && \
> +                                    g_regex_match_simple((pattern), (str), 0, 0)))
>  
>  /**
>   * SECTION:osinfo_db
> -- 
> 1.7.7.1
> 
> _______________________________________________
> virt-tools-list mailing list
> virt-tools-list at redhat.com
> https://www.redhat.com/mailman/listinfo/virt-tools-list
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/virt-tools-list/attachments/20111124/ead08042/attachment.sig>


More information about the virt-tools-list mailing list