This is the mail archive of the
java@gcc.gnu.org
mailing list for the Java project.
Re: found redundant code in file natSystemProperties.cc
- From: Andrew Haley <aph at redhat dot com>
- To: Martin Ettl <ettl dot martin at gmx dot de>
- Cc: java at gcc dot gnu dot org
- Date: Wed, 29 Jul 2009 19:25:05 +0100
- Subject: Re: found redundant code in file natSystemProperties.cc
- References: <20090728042115.158890@gmx.net>
Martin Ettl wrote:
> Hello friends,
>
> i have checked the sources of gcc-4.4.1 with the static code analysis tool cppcheck. It brought up an issue in file gcc-4.4.1/libjava/gnu/classpath/natSystemProperties.cc at line 278. Lets take a look at the sourcecode:
> 278 if (buffer != NULL)
> free (buffer);
> ....
>
> Here the line 278 is redundant, because it is safe to deallocate a NULL-Pointer! In other words, the if-statement can be removed.
Well yes, but it saves a library call.
Harbison and Steele note "If the argument to free is a null pointer
then no action should occur, but this has been known to cause trouble
in some C implementations." This is probably just ancient history,
though.
Andrew.