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

Re: [PATCH 7/9] pretty: support padding placeholders, %< %> and %><

From
Jeff King <peff@peff.net>
Date
Oct 24, 2012, 08:25 UTC
Message-ID
<20121024082512.GA22127@sigill.intra.peff.net>
In-Reply-To
<1348391433-11300-8-git-send-email-pclouds@gmail.com>
On Sun, Sep 23, 2012 at 04:10:31PM +0700, Nguyen Thai Ngoc Duy wrote:
Show 26 quoted lines
> +	else {
> +		int sb_len = sb->len, offset;
> +		switch (c->flush_type) {
> +		case flush_left:
> +			offset = padding - len;
> +			break;
> +		case flush_right:
> +			offset = 0;
> +			break;
> +		case flush_both:
> +			offset = (padding - len) / 2;
> +			break;
> +		case no_flush: /* to make gcc happy */
> +			break;
> +		}
> +		/*
> +		 * we calculate padding in columns, now
> +		 * convert it back to chars
> +		 */
> +		padding = padding - len + local_sb.len;
> +		strbuf_grow(sb, padding);
> +		strbuf_setlen(sb, sb_len + padding);
> +		memset(sb->buf + sb_len, ' ', sb->len - sb_len);
> +		memcpy(sb->buf + sb_len + offset, local_sb.buf,
> +		       local_sb.len);
> +	}

gcc complains (rightly, I think) that offset can be used uninitialized in the final line (looks like it is from the no_flush case). If it is a "can never happen" case that is there to appease gcc in the switch statement, should we drop a die("BUG: XXX") there? If so, what would the XXX be?

-Peff
Previous: Nguyễn Thái Ngọc DuyNext: Nguyễn Thái Ngọc Duy
Message 19 of 21 in “Advanced --oneline layout”
  1. 0/6 Advanced --oneline layoutNguyễn Thái Ngọc Duy, Sep 22, 2012
  2. 1/6 pretty: share code between format_decoration and show_decorationsNguyễn Thái Ngọc Duy, Sep 22, 2012
  3. 2/6 pretty: split parsing %C into a separate functionNguyễn Thái Ngọc Duy, Sep 22, 2012
  4. 3/6 pretty: support %C(auto[,N]) to turn on coloring on next placeholder(s)Nguyễn Thái Ngọc Duy, Sep 22, 2012
  5. 4/6 utf8.c: move display_mode_esc_sequence_len() for use by other functionsNguyễn Thái Ngọc Duy, Sep 22, 2012
  6. 5/6 utf8.c: add utf8_strnwidth() with the ability to skip ansi sequencesNguyễn Thái Ngọc Duy, Sep 22, 2012
  7. 6/6 pretty: support padding placeholders, %< %> and %<>Nguyễn Thái Ngọc Duy, Sep 22, 2012
  8. 7/6 pretty: trim trailing spaces due to paddingNguyễn Thái Ngọc Duy, Sep 22, 2012
  9. 0/9 Advanced --oneline layoutNguyễn Thái Ngọc Duy, Sep 23, 2012
  10. 1/9 pretty: share code between format_decoration and show_decorationsNguyễn Thái Ngọc Duy, Sep 23, 2012
  11. 2/9 pretty: split parsing %C into a separate functionNguyễn Thái Ngọc Duy, Sep 23, 2012
  12. 3/9 pretty: support %C(auto[,N]) to turn on coloring on next placeholder(s)Nguyễn Thái Ngọc Duy, Sep 23, 2012
  13. 4/9 utf8.c: move display_mode_esc_sequence_len() for use by other functionsNguyễn Thái Ngọc Duy, Sep 23, 2012
  14. 5/9 utf8.c: add utf8_strnwidth() with the ability to skip ansi sequencesNguyễn Thái Ngọc Duy, Sep 23, 2012
  15. 6/9 pretty: two phase conversion for non utf-8 commitsNguyễn Thái Ngọc Duy, Sep 23, 2012
  16. Robin RosenbergSep 23, 2012
  17. Nguyen Thai Ngoc DuySep 24, 2012
  18. 7/9 pretty: support padding placeholders, %< %> and %><Nguyễn Thái Ngọc Duy, Sep 23, 2012
  19. Jeff KingOct 24, 2012
  20. 8/9 pretty: support truncating in %>, %< and %><Nguyễn Thái Ngọc Duy, Sep 23, 2012
  21. 9/9 pretty: support %>> that steal trailing spacesNguyễn Thái Ngọc Duy, Sep 23, 2012

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.