Re: [RFC PATCH 2/3] cli: add support for limiting the number of search results
On Fri, 28 Oct 2011 23:59:30 +0300, Jani Nikula j...@nikula.org wrote: @@ -412,6 +413,14 @@ notmuch_search_command (void *ctx, int argc, char *argv[]) fprintf (stderr, Invalid value for --sort: %s\n, opt); return 1; } + } else if (STRNCMP_LITERAL (argv[i], --maxitems=) == 0) { + const char *p; + opt = argv[i] + sizeof (--maxitems=) - 1; + maxitems = strtoul(opt, p, 10); p should be of type `char *', not `const char *', as it will be modified by strtoul. (Otherwise, gcc will produce a warning about this). Cheers, Daniel pgpjX7J5cST8t.pgp Description: PGP signature ___ notmuch mailing list notmuch@notmuchmail.org http://notmuchmail.org/mailman/listinfo/notmuch
Re: [RFC PATCH 2/3] cli: add support for limiting the number of search results
On Sat, 29 Oct 2011 19:30:50 +0200, Daniel Schoepe dan...@schoepe.org wrote: On Fri, 28 Oct 2011 23:59:30 +0300, Jani Nikula j...@nikula.org wrote: @@ -412,6 +413,14 @@ notmuch_search_command (void *ctx, int argc, char *argv[]) fprintf (stderr, Invalid value for --sort: %s\n, opt); return 1; } + } else if (STRNCMP_LITERAL (argv[i], --maxitems=) == 0) { + const char *p; + opt = argv[i] + sizeof (--maxitems=) - 1; + maxitems = strtoul(opt, p, 10); p should be of type `char *', not `const char *', as it will be modified by strtoul. (Otherwise, gcc will produce a warning about this). strtoul() won't touch the data pointed to by p (it only modifies p), so in that sense it could be const, but you're right in that it really should be 'char *', just for a more complicated reason. Thanks for making me look it up: http://c-faq.com/ansi/constmismatch.html (not the best of explanations, perhaps, but gives an idea why the 2nd parameter of strtoul() can't be 'const char **'). BR, Jani. ___ notmuch mailing list notmuch@notmuchmail.org http://notmuchmail.org/mailman/listinfo/notmuch
Re: [RFC PATCH 2/3] cli: add support for limiting the number of search results
On Sat, 29 Oct 2011 23:08:04 +0300, Jani Nikula j...@nikula.org wrote: strtoul() won't touch the data pointed to by p (it only modifies p), so in that sense it could be const, but you're right in that it really should be 'char *', just for a more complicated reason. Thanks for making me look it up: http://c-faq.com/ansi/constmismatch.html (not the best of explanations, perhaps, but gives an idea why the 2nd parameter of strtoul() can't be 'const char **'). Oh, right, thanks for the clarification. As I often do in situations such as this, I confused const char * and char const *. pgpKRtOed6SyQ.pgp Description: PGP signature ___ notmuch mailing list notmuch@notmuchmail.org http://notmuchmail.org/mailman/listinfo/notmuch