public inbox for java@gcc.gnu.org
 help / color / mirror / Atom feed
From: "Martin Ettl" <ettl.martin@gmx.de>
To: java@gcc.gnu.org
Subject: found redundant code in file natSystemProperties.cc
Date: Tue, 28 Jul 2009 04:21:00 -0000	[thread overview]
Message-ID: <20090728042115.158890@gmx.net> (raw)

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:


// ...

  while (buffer != NULL)
    {
      if (getcwd (buffer, buflen) != NULL)
	{
	  SET ("user.dir", buffer);
	  break;
	}
      if (errno != ERANGE)
	break;
      buflen = 2 * buflen;
      char *orig_buf = buffer;
      buffer = (char *) realloc (buffer, buflen);
      if (buffer == NULL)
	free (orig_buf);
    }
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.

Best regards

Ettl Martin


-- 
Neu: GMX Doppel-FLAT mit Internet-Flatrate + Telefon-Flatrate
für nur 19,99 Euro/mtl.!* http://portal.gmx.net/de/go/dsl02

             reply	other threads:[~2009-07-28  4:21 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-07-28  4:21 Martin Ettl [this message]
2009-07-29 18:25 ` Andrew Haley

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=20090728042115.158890@gmx.net \
    --to=ettl.martin@gmx.de \
    --cc=java@gcc.gnu.org \
    /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 read-only IMAP folder(s) and NNTP newsgroup(s).