Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Warning : Possible use of null pointer

Reply
Thread Tools

Warning : Possible use of null pointer

 
 
Alf P. Steinbach
Guest
Posts: n/a
 
      10-05-2005
* HP:
> Possible use of null pointer 'PnoSytGenericTest::_response' in
> left argument to operator '->'
>
> void PnoSytGenericTest::initResponse()
> {
> ENTER_METHOD("SYT_TEST_MGR", PnoSytGenericTest::initResponse);
>
> _response = new AcdMessage();
> _response->header(_data->header());
> (_response->header()).cmdId[0].cmdId = Acd::CMD_RSP;
>
> RETURN_METHOD("SYT_TEST_MGR");
> }


Post the smallest possible complete program that exhibits this problem.

Also, does the following program,

int main()
{
int* p = new int;
*p = 42;
delete p;
}

generate any warning?

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
 
Reply With Quote
 
 
 
 
HP
Guest
Posts: n/a
 
      10-05-2005
Hi All
I dint find any group here reagrding MRI(Microtech research
compiler) compiler.
i am realy only on this group to find out solution.

I cant post the part of code since they are very large.

Please help me out friends

 
Reply With Quote
 
 
 
 
mlimber
Guest
Posts: n/a
 
      10-05-2005
HP wrote:
> Hi All
> I dint find any group here reagrding MRI(Microtech research
> compiler) compiler.
> i am realy only on this group to find out solution.
>
> I cant post the part of code since they are very large.
>
> Please help me out friends


What more can we say that has not already been said?

Cheers! --M

 
Reply With Quote
 
Alf P. Steinbach
Guest
Posts: n/a
 
      10-05-2005
* HP:
> [forgetting to quote]
>
> I cant post the part of code since they are very large.


Quoting myself:
"Post the smallest possible complete program that exhibits this problem."

I can think of numerous reasons why that would be difficult, e.g. you're on a
project where compilers etc. have been installed for you, and you don't know
how to compile a small program that isn't part of the project.

But all those reasons I can think of are reasons why the proper place to seek
help would be in your project organization, not here.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
 
Reply With Quote
 
Karl Heinz Buchegger
Guest
Posts: n/a
 
      10-05-2005
HP wrote:
>
> and 14 to 15 warning is comming in one file and i have near about 35
> files.
> so i cant put those null checking condition everywhere


Why not?
The compiler tells you all the places. You just need to fire up your
editor and insert the checkings. In the time you already wasted today
you could have fixed at least half of them.

35 files isn't much. In my current set of projects I have more then
300 files. If I make some change in the basic structures, the compiler
works for 1 and a half hour and figures out all the places where
this change takes effect. Then an editor session starts and a few hours
later everything is up to date. Not a big deal, you just need to do the
work. Welcome to programming.

--
Karl Heinz Buchegger
http://www.velocityreviews.com/forums/(E-Mail Removed)
 
Reply With Quote
 
HP
Guest
Posts: n/a
 
      10-05-2005
Hi Karl
Thanks for moral ur boosting statements
I'll be realy thankful to you , if you know any tool that
can help me reagarding this issue.

 
Reply With Quote
 
mlimber
Guest
Posts: n/a
 
      10-05-2005
HP wrote:
> Hi Karl
> Thanks for moral ur boosting statements
> I'll be realy thankful to you , if you know any tool that
> can help me reagarding this issue.


Tools needed: an editing program, a keyboard, your fingers, and your
mind. You'll need to adjust the code manually, methinks. The easiest
solution, since your compiler supports exceptions, is to throw your own
exception if new fails likes this:

//...
int *p = new int;
if( !p ) throw MyException();
// use p
// ...

Better would be to use std::auto_ptr, boost::scoped_ptr, or whatever to
manage each new. It gives you exception saftey with little cost, and
you don't have to remember to cleanup after yourself. Also better would
be to use std::bad_alloc and the like if you library has them.

Cheers! --M

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
possible NULL && dereferencing NULL pointer Mark C Programming 8 02-01-2012 03:15 PM
pointer to pointer intialize to NULL but still point to NULL Christopher C++ 4 07-09-2011 12:35 AM
Null pointer (NULL array pointer is passed) aneuryzma C++ 3 06-16-2008 05:48 AM
"stringObj == null" vs "stringObj.equals(null)", for null check?? qazmlp1209@rediffmail.com Java 5 03-29-2006 10:37 PM
NULL macro vs. 0 as null pointer? Ken C++ 69 07-31-2004 04:45 AM



Advertisments