git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v2 0/7] grep.c: teach --column to 'git-grep(1)'

From
Jeff King <peff@peff.net>
Date
Jun 21, 2018, 12:01 UTC
Message-ID
<20180621120159.GC15293@sigill.intra.peff.net>
In-Reply-To
<20180621115302.GB15293@sigill.intra.peff.net>
On Thu, Jun 21, 2018 at 07:53:02AM -0400, Jeff King wrote:
Show 10 quoted lines
> > @@ -1429,7 +1447,7 @@ static void show_line(struct grep_opt *opt, char *bol, char *eol,
> >  	 */
> >  	if (opt->columnnum && cno) {
> >  		char buf[32];
> > -		xsnprintf(buf, sizeof(buf), "%d", cno);
> > +		xsnprintf(buf, sizeof(buf), "%zu", cno);
> 
> Unfortunately %z isn't portable. You have to use:
> 
>   xsnprintf(buf, sizeof(buf), "%"PRIuMAX, (uintmax_t)cno);

To clarify: yes, it is in C99. But traditionally we have not required that.

This might be a candidate for another "weather balloon" patch to see if anybody complains, though. The last time time we dealt with this in a major way was over 7 years ago in 28bd70d811 (unbreak and eliminate NO_C99_FORMAT, 2011-03-16).

I know Johannes switched out some "%lu" for PRIuMAX as recently as last August[1], but I think that is more about the Windows size_t not matching "unsigned long", and the decision to use PRIuMAX was to match the existing codebase. AFAIK %zu is available on Windows.

-Peff
[1] https://public-inbox.org/git/alpine.DEB.2.21.1.1708100011391.11175@virtualbox/
Previous: Jeff KingNext: Johannes Schindelin
Message 40 of 56 in “grep.c: teach --column to 'git-grep(1)'”
  1. 0/7 grep.c: teach --column to 'git-grep(1)'Taylor Blau, Jun 18, 2018
  2. 1/7 Documentation/config.txt: camel-case lineNumber for consistencyTaylor Blau, Jun 18, 2018
  3. 2/7 grep.c: expose {,inverted} match column in match_line()Taylor Blau, Jun 18, 2018
  4. Junio C HamanoJun 19, 2018
  5. Taylor BlauJun 19, 2018
  6. 3/7 grep.[ch]: extend grep_opt to allow showing matched columnTaylor Blau, Jun 18, 2018
  7. 4/7 grep.c: display column number of first matchTaylor Blau, Jun 18, 2018
  8. Jeff KingJun 19, 2018
  9. Taylor BlauJun 19, 2018
  10. 5/7 builtin/grep.c: add '--column' option to 'git-grep(1)'Taylor Blau, Jun 18, 2018
  11. 6/7 grep.c: add configuration variables to show matched optionTaylor Blau, Jun 18, 2018
  12. 7/7 contrib/git-jump/git-jump: jump to exact locationTaylor Blau, Jun 18, 2018
  13. Jeff KingJun 19, 2018
  14. René ScharfeJun 19, 2018
  15. Taylor BlauJun 19, 2018
  16. René ScharfeJun 19, 2018
  17. René ScharfeJun 19, 2018
  18. Jeff KingJun 19, 2018
  19. Taylor BlauJun 19, 2018
  20. Junio C HamanoJun 19, 2018
  21. Taylor BlauJun 19, 2018
  22. Jeff KingJun 19, 2018
  23. Junio C HamanoJun 19, 2018
  24. René ScharfeJun 19, 2018
  25. Jeff KingJun 19, 2018
  26. René ScharfeJun 19, 2018
  27. Junio C HamanoJun 19, 2018
  28. Junio C HamanoJun 19, 2018
  29. Taylor BlauJun 19, 2018
  30. Taylor BlauJun 19, 2018
  31. 0/7 grep.c: teach --column to 'git-grep(1)'Taylor Blau, Jun 20, 2018
  32. 1/7 Documentation/config.txt: camel-case lineNumber for consistencyTaylor Blau, Jun 20, 2018
  33. 2/7 grep.c: expose {,inverted} match column in match_line()Taylor Blau, Jun 20, 2018
  34. 3/7 grep.[ch]: extend grep_opt to allow showing matched columnTaylor Blau, Jun 20, 2018
  35. 4/7 grep.c: display column number of first matchTaylor Blau, Jun 20, 2018
  36. 6/7 grep.c: add configuration variables to show matched optionTaylor Blau, Jun 20, 2018
  37. 7/7 contrib/git-jump/git-jump: jump to exact locationTaylor Blau, Jun 20, 2018
  38. 5/7 builtin/grep.c: add '--column' option to 'git-grep(1)'Taylor Blau, Jun 20, 2018
  39. Jeff KingJun 21, 2018
  40. Jeff KingJun 21, 2018
  41. Johannes SchindelinJun 22, 2018
  42. Jeff KingJun 22, 2018
  43. Junio C HamanoJun 21, 2018
  44. Taylor BlauJun 21, 2018
  45. Jeff KingJun 22, 2018
  46. 0/7 grep.c: teach --column to 'git-grep(1)'Taylor Blau, Jun 22, 2018
  47. 1/7 Documentation/config.txt: camel-case lineNumber for consistencyTaylor Blau, Jun 22, 2018
  48. 2/7 grep.c: expose {,inverted} match column in match_line()Taylor Blau, Jun 22, 2018
  49. 3/7 grep.[ch]: extend grep_opt to allow showing matched columnTaylor Blau, Jun 22, 2018
  50. 4/7 grep.c: display column number of first matchTaylor Blau, Jun 22, 2018
  51. 5/7 builtin/grep.c: add '--column' option to 'git-grep(1)'Taylor Blau, Jun 22, 2018
  52. 7/7 contrib/git-jump/git-jump: jump to exact locationTaylor Blau, Jun 22, 2018
  53. 6/7 grep.c: add configuration variables to show matched optionTaylor Blau, Jun 22, 2018
  54. Jeff KingJun 25, 2018
  55. Taylor BlauJun 25, 2018
  56. Junio C HamanoJun 26, 2018

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.