found redundant code in file natSystemProperties.cc

"Martin Ettl" <[email protected]>
Newsgroups gmane.comp.gcc.java.devel
Message-ID <[email protected]>
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.