git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andreas Ericsson <ae@op5.se>
To: Joachim Schmitz <jojo@schmitz-digital.de>
Cc: 'Junio C Hamano' <gitster@pobox.com>,
	'Johannes Sixt' <j.sixt@viscovery.net>,
	'Jan Engelhardt' <jengelh@inai.de>,
	git@vger.kernel.org
Subject: Re: git on HP NonStop
Date: Thu, 23 Aug 2012 10:23:35 +0200	[thread overview]
Message-ID: <5035E887.3030209@op5.se> (raw)
In-Reply-To: <002b01cd8084$8459abc0$8d0d0340$@schmitz-digital.de>

On 08/22/2012 06:38 PM, Joachim Schmitz wrote:
> 
> 
>> -----Original Message-----
>> From: Junio C Hamano [mailto:gitster@pobox.com]
>> Sent: Tuesday, August 21, 2012 4:06 AM
>> To: Joachim Schmitz
>> Cc: 'Johannes Sixt'; 'Jan Engelhardt'; git@vger.kernel.org
>> Subject: Re: git on HP NonStop
>>
>> "Joachim Schmitz" <jojo@schmitz-digital.de> writes:
>>
>>> OK, so let's have a look at code, current git, builtin/cat-file.c,
>>> line 196:
>>>          void *contents = contents;
>>>
>>> This variable is set later in an if branch (if (print_contents ==
>>> BATCH), but not in the else branch. It is later used always under the
>>> same condition as the one under which it is set.
>>> Apparently is is malloc_d storage (there a "free(content);"), so
>>> there's no harm al all in initializing it with NULL, even if it only
>>> appeases a stupid compiler.
>>
>> It actually is harmful.  See below.
> 
> Harmful to initialize with NULL or to use that undefined behavoir?
> 
> I checked what our compiler does here: after having warned about "vlues us
> used before it is set: it actually dies seem to have initializes the value
> to 0 resp. NULL.
> So here there's no harm done in avoiding undefined behavior and set it to 0
> resp NULL in the first place.
> 

There is harm in tricking future programmers into thinking that the
initialization actually means something, which some of them do.

It's unlikely that you're the one to maintain that code forever, and
the "var = var" idiom is used widely within git with a clear meaning
as a hint to programmers who read a bit of git code. If they aren't
used to that idiom, they usually investigate it in the code and
pretty quickly realize that what it means.


-- 
Andreas Ericsson                   andreas.ericsson@op5.se
OP5 AB                             www.op5.se
Tel: +46 8-230225                  Fax: +46 8-230231

Considering the successes of the wars on alcohol, poverty, drugs and
terror, I think we should give some serious thought to declaring war
on peace.

  reply	other threads:[~2012-08-23  8:23 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <001101cd79f2$f21b3bd0$d651b370$@schmitz-digital.de>
     [not found] ` <7vr4r98rfd.fsf@alter.siamese.dyndns.org>
2012-08-14 15:52   ` git on HP NonStop Joachim Schmitz
2012-08-19 16:25     ` Jan Engelhardt
2012-08-20 10:36       ` Joachim Schmitz
2012-08-20 10:56         ` Johannes Sixt
2012-08-20 11:27           ` Joachim Schmitz
2012-08-20 16:29           ` Junio C Hamano
2012-08-20 20:51             ` Joachim Schmitz
2012-08-21  2:06               ` Junio C Hamano
2012-08-22 16:38                 ` Joachim Schmitz
2012-08-23  8:23                   ` Andreas Ericsson [this message]
2012-08-23  9:23                     ` Joachim Schmitz

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=5035E887.3030209@op5.se \
    --to=ae@op5.se \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=j.sixt@viscovery.net \
    --cc=jengelh@inai.de \
    --cc=jojo@schmitz-digital.de \
    /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;
as well as URLs for NNTP newsgroup(s).