Git development
 help / color / mirror / Atom feed
From: Johannes Schindelin <Johannes.Schindelin@gmx.de>
To: "René Scharfe" <l.s.r@web.de>
Cc: Pranit Bauva <pranit.bauva@gmail.com>,
	git@vger.kernel.org, Junio C Hamano <gitster@pobox.com>
Subject: Re: [PATCH] fixup! bisect--helper: `bisect_next_check` & bisect_voc shell function in C
Date: Mon, 13 Feb 2017 17:23:14 +0100 (CET)	[thread overview]
Message-ID: <alpine.DEB.2.20.1702131722350.3496@virtualbox> (raw)
In-Reply-To: <128b4de6-7b8e-27b9-414d-c6c6529cb491@web.de>

[-- Attachment #1: Type: text/plain, Size: 1670 bytes --]

Hi René,

On Fri, 10 Feb 2017, René Scharfe wrote:

> Am 10.02.2017 um 15:20 schrieb Johannes Schindelin:
> > It is curious that only MacOSX builds trigger an error about this, both
> > GCC and Clang, but not Linux GCC nor Clang (see
> > https://travis-ci.org/git/git/jobs/200182819#L1152 for details):
> >
> > builtin/bisect--helper.c:299:6: error: variable 'good_syn' is used
> >   uninitialized whenever 'if' condition is true
> >   [-Werror,-Wsometimes-uninitialized]
> >         if (missing_good && !missing_bad && current_term &&
> >             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> > builtin/bisect--helper.c:350:7: note: uninitialized use occurs here
> >         if (!good_syn)
> >              ^~~~~~~~
> 
> The only way that good_syn could be used in the if block is by going to the
> label finish, which does the following before returning:
> 
> 	if (!bad_ref)
> 		free(bad_ref);
> 	if (!good_glob)
> 		free(good_glob);
> 	if (!bad_syn)
> 		free(bad_syn);
> 	if (!good_syn)
> 		free(good_syn);
> 
> On Linux that code is elided completely -- freeing NULL is a no-op.  I guess
> free(3) has different attributes on OS X and compilers don't dare to optimize
> it away there.
> 
> So instead of calling free(3) only in the case when we did not allocate memory
> (which makes no sense and leaks) we should either call it in the opposite
> case, or (preferred) unconditionally, as it can handle the NULL case itself.
> Once that's fixed initialization will be required even on Linux.

Exactly, free(NULL) is a no-op. The problem before this fixup was that
good_syn was not initialized to NULL.

Ciao,
Dscho

  reply	other threads:[~2017-02-13 16:23 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-10 14:20 [PATCH] fixup! bisect--helper: `bisect_next_check` & bisect_voc shell function in C Johannes Schindelin
2017-02-10 15:30 ` Pranit Bauva
2017-02-10 20:47 ` René Scharfe
2017-02-13 16:23   ` Johannes Schindelin [this message]
2017-02-13 18:27     ` René Scharfe
2017-02-13 19:14       ` Junio C Hamano
2017-02-13 19:34         ` Pranit Bauva
2017-02-19  2:06         ` Junio C Hamano

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

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

  git send-email \
    --in-reply-to=alpine.DEB.2.20.1702131722350.3496@virtualbox \
    --to=johannes.schindelin@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=l.s.r@web.de \
    --cc=pranit.bauva@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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox