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/