git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: John Keeping <john@keeping.me.uk>
To: Ramkumar Ramachandra <artagnon@gmail.com>
Cc: "Antoine Pelisse" <apelisse@gmail.com>,
	"Git List" <git@vger.kernel.org>,
	"Junio C Hamano" <gitster@pobox.com>,
	"Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: Re: [PATCH 1/3] for-each-ref: introduce %C(...) for color
Date: Sat, 25 May 2013 13:20:02 +0100	[thread overview]
Message-ID: <20130525122002.GI27005@serenity.lan> (raw)
In-Reply-To: <CALkWK0=16dmz548TQoj5YKp0dai7p1dpYAdXiWnnpiQdzyYHQg@mail.gmail.com>

On Sat, May 25, 2013 at 05:20:29PM +0530, Ramkumar Ramachandra wrote:
> Antoine Pelisse wrote:
> > Is it not possible for "color" to be used uninitialized here ?
> 
> My compiler didn't complain; what am I missing?  Doesn't the
> declaration char color[COLOR_MAXLEN]; initialize an empty string?

Why would it?  The variable's begin allocated on the stack and the C
standard only zero-initializes variables with static storage duration;
Section 6.7.9 of the C11 standard says:

    If an object that has automatic storage duration is not initialized
    explicitly, its value is indeterminate.


I suspect the compiler doesn't complain because there is a path through
the function that initializes color before reading it (if we hit the
"if" branch in the loop before the "else" branch) and the compile
assumes that there is something in the function's contract that
guarantees that we follow this path.  But I don't think that's correct
so you do need to initialize color to the empty string.

> More importantly, aren't there numerous instances of this in the
> codebase?

Care to point at one?  I had a quick look and all places I inspected are
either static or write to the array before reading it.

  reply	other threads:[~2013-05-25 12:20 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-24 14:19 [PATCH v2 0/3] Towards a useable git-branch Ramkumar Ramachandra
2013-05-24 14:19 ` [PATCH 1/3] for-each-ref: introduce %C(...) for color Ramkumar Ramachandra
2013-05-24 20:56   ` Antoine Pelisse
2013-05-25 11:50     ` Ramkumar Ramachandra
2013-05-25 12:20       ` John Keeping [this message]
2013-05-25 12:54         ` Ramkumar Ramachandra
2013-05-25 12:35       ` Antoine Pelisse
2013-05-24 23:41   ` David Aguilar
2013-05-25 11:51     ` Ramkumar Ramachandra
2013-05-25  6:29   ` Eric Sunshine
2013-05-24 14:19 ` [PATCH 2/3] for-each-ref: introduce %(HEAD) marker Ramkumar Ramachandra
2013-05-24 20:28   ` Philip Oakley
2013-05-24 14:19 ` [PATCH 3/3] for-each-ref: introduce %(upstream:track[short]) Ramkumar Ramachandra
2013-05-24 15:27 ` [PATCH v2 0/3] Towards a useable git-branch Duy Nguyen
2013-05-24 15:58   ` Ramkumar Ramachandra
2013-05-24 17:52   ` Junio C Hamano
2013-05-24 18:01     ` Ramkumar Ramachandra
2013-05-24 18:08     ` Ramkumar Ramachandra
2013-05-24 22:51 ` Duy Nguyen
2013-05-25  6:26   ` Duy Nguyen
2013-05-25 11:35     ` Duy Nguyen
2013-05-25 11:48       ` Ramkumar Ramachandra
2013-05-28 14:01         ` Ramkumar Ramachandra
2013-05-28 14:24           ` Ramkumar Ramachandra
2013-05-30  4:19             ` Duy Nguyen
2013-06-04 12:52               ` Ramkumar Ramachandra
2013-06-04 13:11                 ` Duy Nguyen
2013-05-28 14:28           ` Ramkumar Ramachandra
2013-05-29  3:04             ` Duy Nguyen
2013-05-29 21:12               ` Ramkumar Ramachandra
2013-05-29  3:22           ` Duy Nguyen
  -- strict thread matches above, loose matches on Subject: below --
2013-09-27 12:10 [PATCH 0/3] Juggling between hot branches Ramkumar Ramachandra
2013-09-27 12:10 ` [PATCH 1/3] for-each-ref: introduce %C(...) for color Ramkumar Ramachandra
2013-09-27 13:16   ` Phil Hord
2013-10-31  9:46 [PATCH (resend) 0/3] Minor f-e-r enhacements Ramkumar Ramachandra
2013-10-31  9:46 ` [PATCH 1/3] for-each-ref: introduce %C(...) for color Ramkumar Ramachandra
2013-10-31 20:50   ` Junio C Hamano
2013-11-01  8:37     ` Ramkumar Ramachandra
2013-11-01 15:05       ` Junio C Hamano
2013-11-02  6:02         ` Ramkumar Ramachandra
2013-11-04 18:17           ` Junio C Hamano
2013-11-07  6:36             ` Ramkumar Ramachandra
2013-11-07 18:02               ` Junio C Hamano
2013-11-08 12:14                 ` Ramkumar Ramachandra
2013-11-08 17:30                   ` Junio C Hamano
2013-11-12  3:38                     ` Ramkumar Ramachandra

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20130525122002.GI27005@serenity.lan \
    --to=john@keeping.me.uk \
    --cc=apelisse@gmail.com \
    --cc=artagnon@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=pclouds@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).