user980020
user980020

Reputation: 85

c++ code review

if (ad && (etag = strrcasestr_len(ad,strlen(ad),
                "</XHTML-STRIPONREPLY>", 21))) {

here ad and etag are const char*

when the custom function strrcasestr_len returns NULL

will the expression evaluate to (ad && null)

Upvotes: 0

Views: 764

Answers (3)

Scott Langham
Scott Langham

Reputation: 60441

If I was code reviewing that code, I'd tell the author to rewrite it so that it's clear what the behaviour is. Due to the potential for confusion, use of assignment operators in conditional expressions should be ruled out by coding standards.

The behaviour will be well defined, but that's not good enough reason to write it. The code needs to be clear. Breaking it into two statements is probably easier to follow:

etag = strrcasestr_len(ad, strlen(ad), "</XHTML-STRIPONREPLY>", 21);

[No idea what's going on... I can't write the if statement here as stackoverflow rejects the edit if I do]

Upvotes: 0

Mat
Mat

Reputation: 206909

NULL is false in boolean context, so the expression will be false. (i.e. the if branch will not be taken.)

Upvotes: 4

Henrik
Henrik

Reputation: 23324

...which will evaluate to false, yes. Note also, that etag = strrcasestr_len(...) will not be evaluated at all, if ad is NULL.

Upvotes: 1

Related Questions