Rather than having malloc() function calls scattered throughout the test driver, I was wondering if a conventional malloc() wrapper wouldn't take care of a lot of this error checking and null pointer dereference warnings. A conventional Unix malloc() wrapper checks the return value and just prints a diagnostic and exits the program if it is null.
Brad. > -----Original Message----- > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] > Sent: Tuesday, April 22, 2008 5:39 PM > To: [EMAIL PROTECTED] > Subject: svn commit: r650698 - > /stdcxx/branches/4.2.x/tests/src/cmdopt.cpp > > Author: sebor > Date: Tue Apr 22 16:38:40 2008 > New Revision: 650698 > > URL: http://svn.apache.org/viewvc?rev=650698&view=rev > Log: > 2008-04-22 Martin Sebor <[EMAIL PROTECTED]> > > STDCXX-754 > * tests/src/cmdopt.cpp (rw_vsetopts): Handled malloc() failure. > Added an assertion to silence a bogus HP aCC 6/cadvise warning > #20200-D: Potential null pointer dereference. Unfortunately, > with the one gone another bogus one pops up... > > Modified: > stdcxx/branches/4.2.x/tests/src/cmdopt.cpp > > Modified: stdcxx/branches/4.2.x/tests/src/cmdopt.cpp > URL: > http://svn.apache.org/viewvc/stdcxx/branches/4.2.x/tests/src/c > mdopt.cpp?rev=650698&r1=650697&r2=650698&view=diff > ============================================================== > ================ > --- stdcxx/branches/4.2.x/tests/src/cmdopt.cpp (original) > +++ stdcxx/branches/4.2.x/tests/src/cmdopt.cpp Tue Apr 22 > 16:38:40 2008 > @@ -20,7 +20,7 @@ > * implied. See the License for the specific language > governing > * permissions and limitations under the License. > * > - * Copyright 2005-2006 Rogue Wave Software. > + * Copyright 2005-2008 Rogue Wave Software, Inc. > * > > ************************************************************** > ************/ > > @@ -518,6 +518,8 @@ > lopt = lastopt->loptbuf_; > else { > lopt = (char*)malloc (optlen + 1); > + if (0 == lopt) > + return -1; // error > lastopt->lopt_ = lopt; > } > > @@ -533,6 +535,8 @@ > lastopt->maxcount_ = 1; > > int arg_is_callback = true; > + > + RW_ASSERT (0 != next); > > if ('#' == *next) { > // examples of option specification: > > >
