[PATCH 1/2] cli: fix notmuch top level argument parsing

Michal Nazarewicz mina86 at mina86.com
Mon Dec 3 13:32:52 PST 2012


On Mon, Dec 03 2012, Jani Nikula wrote:
> Use strcmp instead of STRNCMP_LITERAL, which matches the prefix
> instead of the whole argument.

Perhaps add and use this instead:

#define STRCMP_LITERAL(var, literal) \
    strncmp ((var), (literal), sizeof (literal))

Than again, it's argument parsing so hardly a performance critical path,
so maybe readability is more important.

> ---
>  notmuch.c |    4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/notmuch.c b/notmuch.c
> index 477a09c..4ff66e3 100644
> --- a/notmuch.c
> +++ b/notmuch.c
> @@ -245,10 +245,10 @@ main (int argc, char *argv[])
>      if (argc == 1)
>  	return notmuch (local);
>  
> -    if (STRNCMP_LITERAL (argv[1], "--help") == 0)
> +    if (strcmp (argv[1], "--help") == 0)
>  	return notmuch_help_command (NULL, argc - 1, &argv[1]);
>  
> -    if (STRNCMP_LITERAL (argv[1], "--version") == 0) {
> +    if (strcmp (argv[1], "--version") == 0) {
>  	printf ("notmuch " STRINGIFY(NOTMUCH_VERSION) "\n");
>  	return 0;
>      }

-- 
Best regards,                                         _     _
.o. | Liege of Serenely Enlightened Majesty of      o' \,=./ `o
..o | Computer Science,  Michał “mina86” Nazarewicz    (o o)
ooo +----<email/xmpp: mpn at google.com>--------------ooO--(_)--Ooo--
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 835 bytes
Desc: not available
URL: <http://notmuchmail.org/pipermail/notmuch/attachments/20121203/dcf0d1c3/attachment.pgp>


More information about the notmuch mailing list