You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@stdcxx.apache.org by Scott Zhong <Sc...@roguewave.com> on 2008/03/20 18:50:05 UTC

[TESTCASE] STDCXX-750 [HP aCC 6.16] Potential null pointer dereference in aliases.cpp

cat /build/scottz/t2.cpp && aCC -V && aCC -c  +w  /build/scottz/t2.cpp 
#include <cstdlib>

int main()
{
  static char * test = 0;
  if (!test) {
     test = (char *)std::malloc (12345);
     *test = '\0';
  }

  return 0;
}
aCC: HP C/aC++ B3910B A.06.16 [Nov 26 2007]
"/build/scottz/t2.cpp", line 8, procedure main: warning #20200-D:
Potential
          null pointer dereference through test is detected (null
          definition:/build/scottz/t2.cpp, line 7)

this test case shows that the warning is bogus because the pointer
"test" is pointing to a valid location in memory after std::malloc is
performed.

Re: [TESTCASE] STDCXX-750 [HP aCC 6.16] Potential null pointer dereference in aliases.cpp

Posted by Martin Sebor <se...@roguewave.com>.
FYI: This was simple enough that I made the change myself:
   http://svn.apache.org/viewvc?rev=639452&view=rev

Martin

Martin Sebor wrote:
> Scott Zhong wrote:
>> Martin, would you suggest that there should be a check after malloc and
>> throw bad_alloc?
> 
> I think we should just use the new expression instead of calling
> malloc. That way we don't need to check. Unless we call malloc()
> in the rest of the program for some reason.
> 
> Martin
> 
>>
>>> -----Original Message-----
>>> From: Martin Sebor [mailto:msebor@gmail.com] On Behalf Of Martin Sebor
>>> Sent: Thursday, March 20, 2008 12:02 PM
>>> To: dev@stdcxx.apache.org
>>> Subject: Re: [TESTCASE] STDCXX-750 [HP aCC 6.16] Potential null
>> pointer
>>> dereference in aliases.cpp
>>>
>>> I was going to say this is the same bug as STDCXX-764:
>>>    http://issues.apache.org/jira/browse/STDCXX-764
>>> but after looking at it more closely I believe the compiler
>>> is correct in this case because malloc() returns 0 when it
>>> fails to allocate memory. The warning could be clearer about
>>> it.
>>>
>>> Martin
>>>
>>> Scott Zhong wrote:
>>>> cat /build/scottz/t2.cpp && aCC -V && aCC -c  +w
>> /build/scottz/t2.cpp
>>>> #include <cstdlib>
>>>>
>>>> int main()
>>>> {
>>>>   static char * test = 0;
>>>>   if (!test) {
>>>>      test = (char *)std::malloc (12345);
>>>>      *test = '\0';
>>>>   }
>>>>
>>>>   return 0;
>>>> }
>>>> aCC: HP C/aC++ B3910B A.06.16 [Nov 26 2007]
>>>> "/build/scottz/t2.cpp", line 8, procedure main: warning #20200-D:
>>>> Potential
>>>>           null pointer dereference through test is detected (null
>>>>           definition:/build/scottz/t2.cpp, line 7)
>>>>
>>>> this test case shows that the warning is bogus because the pointer
>>>> "test" is pointing to a valid location in memory after std::malloc
>> is
>>>> performed.
>>>>
>>
>>
> 
> 


RE: [TESTCASE] STDCXX-750 [HP aCC 6.16] Potential null pointer dereference in aliases.cpp

Posted by Scott Zhong <Sc...@roguewave.com>.
Just to verify, changing

slocname = (char*)std::malloc (16384);

to

slocname = new char[16384];

is sufficient?

> -----Original Message-----
> From: Martin Sebor [mailto:msebor@gmail.com] On Behalf Of Martin Sebor
> Sent: Thursday, March 20, 2008 2:36 PM
> To: dev@stdcxx.apache.org
> Subject: Re: [TESTCASE] STDCXX-750 [HP aCC 6.16] Potential null
pointer
> dereference in aliases.cpp
> 
> Scott Zhong wrote:
> > Martin, would you suggest that there should be a check after malloc
and
> > throw bad_alloc?
> 
> I think we should just use the new expression instead of calling
> malloc. That way we don't need to check. Unless we call malloc()
> in the rest of the program for some reason.
> 
> Martin
> 
> >
> >> -----Original Message-----
> >> From: Martin Sebor [mailto:msebor@gmail.com] On Behalf Of Martin
Sebor
> >> Sent: Thursday, March 20, 2008 12:02 PM
> >> To: dev@stdcxx.apache.org
> >> Subject: Re: [TESTCASE] STDCXX-750 [HP aCC 6.16] Potential null
> > pointer
> >> dereference in aliases.cpp
> >>
> >> I was going to say this is the same bug as STDCXX-764:
> >>    http://issues.apache.org/jira/browse/STDCXX-764
> >> but after looking at it more closely I believe the compiler
> >> is correct in this case because malloc() returns 0 when it
> >> fails to allocate memory. The warning could be clearer about
> >> it.
> >>
> >> Martin
> >>
> >> Scott Zhong wrote:
> >>> cat /build/scottz/t2.cpp && aCC -V && aCC -c  +w
> > /build/scottz/t2.cpp
> >>> #include <cstdlib>
> >>>
> >>> int main()
> >>> {
> >>>   static char * test = 0;
> >>>   if (!test) {
> >>>      test = (char *)std::malloc (12345);
> >>>      *test = '\0';
> >>>   }
> >>>
> >>>   return 0;
> >>> }
> >>> aCC: HP C/aC++ B3910B A.06.16 [Nov 26 2007]
> >>> "/build/scottz/t2.cpp", line 8, procedure main: warning #20200-D:
> >>> Potential
> >>>           null pointer dereference through test is detected (null
> >>>           definition:/build/scottz/t2.cpp, line 7)
> >>>
> >>> this test case shows that the warning is bogus because the pointer
> >>> "test" is pointing to a valid location in memory after std::malloc
> > is
> >>> performed.
> >>>
> >
> >


Re: [TESTCASE] STDCXX-750 [HP aCC 6.16] Potential null pointer dereference in aliases.cpp

Posted by Martin Sebor <se...@roguewave.com>.
Scott Zhong wrote:
> Martin, would you suggest that there should be a check after malloc and
> throw bad_alloc?

I think we should just use the new expression instead of calling
malloc. That way we don't need to check. Unless we call malloc()
in the rest of the program for some reason.

Martin

> 
>> -----Original Message-----
>> From: Martin Sebor [mailto:msebor@gmail.com] On Behalf Of Martin Sebor
>> Sent: Thursday, March 20, 2008 12:02 PM
>> To: dev@stdcxx.apache.org
>> Subject: Re: [TESTCASE] STDCXX-750 [HP aCC 6.16] Potential null
> pointer
>> dereference in aliases.cpp
>>
>> I was going to say this is the same bug as STDCXX-764:
>>    http://issues.apache.org/jira/browse/STDCXX-764
>> but after looking at it more closely I believe the compiler
>> is correct in this case because malloc() returns 0 when it
>> fails to allocate memory. The warning could be clearer about
>> it.
>>
>> Martin
>>
>> Scott Zhong wrote:
>>> cat /build/scottz/t2.cpp && aCC -V && aCC -c  +w
> /build/scottz/t2.cpp
>>> #include <cstdlib>
>>>
>>> int main()
>>> {
>>>   static char * test = 0;
>>>   if (!test) {
>>>      test = (char *)std::malloc (12345);
>>>      *test = '\0';
>>>   }
>>>
>>>   return 0;
>>> }
>>> aCC: HP C/aC++ B3910B A.06.16 [Nov 26 2007]
>>> "/build/scottz/t2.cpp", line 8, procedure main: warning #20200-D:
>>> Potential
>>>           null pointer dereference through test is detected (null
>>>           definition:/build/scottz/t2.cpp, line 7)
>>>
>>> this test case shows that the warning is bogus because the pointer
>>> "test" is pointing to a valid location in memory after std::malloc
> is
>>> performed.
>>>
> 
> 


RE: [TESTCASE] STDCXX-750 [HP aCC 6.16] Potential null pointer dereference in aliases.cpp

Posted by Scott Zhong <Sc...@roguewave.com>.
Martin, would you suggest that there should be a check after malloc and
throw bad_alloc?

> -----Original Message-----
> From: Martin Sebor [mailto:msebor@gmail.com] On Behalf Of Martin Sebor
> Sent: Thursday, March 20, 2008 12:02 PM
> To: dev@stdcxx.apache.org
> Subject: Re: [TESTCASE] STDCXX-750 [HP aCC 6.16] Potential null
pointer
> dereference in aliases.cpp
> 
> I was going to say this is the same bug as STDCXX-764:
>    http://issues.apache.org/jira/browse/STDCXX-764
> but after looking at it more closely I believe the compiler
> is correct in this case because malloc() returns 0 when it
> fails to allocate memory. The warning could be clearer about
> it.
> 
> Martin
> 
> Scott Zhong wrote:
> > cat /build/scottz/t2.cpp && aCC -V && aCC -c  +w
/build/scottz/t2.cpp
> > #include <cstdlib>
> >
> > int main()
> > {
> >   static char * test = 0;
> >   if (!test) {
> >      test = (char *)std::malloc (12345);
> >      *test = '\0';
> >   }
> >
> >   return 0;
> > }
> > aCC: HP C/aC++ B3910B A.06.16 [Nov 26 2007]
> > "/build/scottz/t2.cpp", line 8, procedure main: warning #20200-D:
> > Potential
> >           null pointer dereference through test is detected (null
> >           definition:/build/scottz/t2.cpp, line 7)
> >
> > this test case shows that the warning is bogus because the pointer
> > "test" is pointing to a valid location in memory after std::malloc
is
> > performed.
> >


Re: [TESTCASE] STDCXX-750 [HP aCC 6.16] Potential null pointer dereference in aliases.cpp

Posted by Martin Sebor <se...@roguewave.com>.
I was going to say this is the same bug as STDCXX-764:
   http://issues.apache.org/jira/browse/STDCXX-764
but after looking at it more closely I believe the compiler
is correct in this case because malloc() returns 0 when it
fails to allocate memory. The warning could be clearer about
it.

Martin

Scott Zhong wrote:
> cat /build/scottz/t2.cpp && aCC -V && aCC -c  +w  /build/scottz/t2.cpp 
> #include <cstdlib>
> 
> int main()
> {
>   static char * test = 0;
>   if (!test) {
>      test = (char *)std::malloc (12345);
>      *test = '\0';
>   }
> 
>   return 0;
> }
> aCC: HP C/aC++ B3910B A.06.16 [Nov 26 2007]
> "/build/scottz/t2.cpp", line 8, procedure main: warning #20200-D:
> Potential
>           null pointer dereference through test is detected (null
>           definition:/build/scottz/t2.cpp, line 7)
> 
> this test case shows that the warning is bogus because the pointer
> "test" is pointing to a valid location in memory after std::malloc is
> performed.
>