Warning : Possible use of null pointer

A

Alf P. Steinbach

* 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?
 
H

HP

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
 
M

mlimber

HP said:
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
 
A

Alf P. Steinbach

* 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.
 
K

Karl Heinz Buchegger

HP said:
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.
 
H

HP

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.
 
M

mlimber

HP said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,049
Latest member
Allen00Reed

Latest Threads

Top