Reputation: 761
I have a code like shown below
if ((client == NULL) || (client->type == Leave_Agent)) {
but when i changed it with following code i am getting errors in event logs the modified code is shown below
if (((client == NULL)|| (client->type == Leave_Agent)) && (client->type == 0)) {
errors in event log is
Faulting application name: test.exe, version: 8.0.16.0, time stamp: 0x5036427e
Can any body guide me how to fix this, which stopping my application.The && operator will make any issues in c++ ?
Upvotes: 0
Views: 236
Reputation: 227410
The problem is that you can reach this
agent->type == 0
when agent==NULL
.
I cannot comment on how to fix without knowing what behaviour you expect. At the very least you should make sure agent
is not dereferenced if it is ==NULL
.
Upvotes: 2
Reputation: 182639
if (((agent == NULL)|| (agent->type == SPUES_ntAgent)) && (agent->type == 0))
If agent is NULL
then the left side of &&
will always be true and agent->type
will always be accessed. So a NULL
agent ensures a NULL
dereference.
You should change your code to ensure it only gets dereferenced if it's not NULL.
Upvotes: 3
Reputation: 88711
I think you wanted to move the () around so that you never dereference the pointer if it's NULL:
if ((agent == NULL)|| ((agent->type == SPUES_ntAgent) && (agent->type == 0))) {
Upvotes: 2