Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 860847
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T08:52:52+00:00 2026-05-15T08:52:52+00:00

Came across a line in OpenSSL that made me do a double take… if

  • 0

Came across a line in OpenSSL that made me do a double take…

if (!*pos)
  return NULL;
if (!*pos || ((*pos)->flags == FLAGS))
  return blah;

Is there a (performance/security/concurrecy) difference in doing that instead of:

if (!*pos) 
  return NULL;
if (*pos && ((*pos)->flags == FLAGS))
  return blah;

Thanks,
Chenz

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T08:52:53+00:00Added an answer on May 15, 2026 at 8:52 am

    Seems like the first line obsoletes the first condition of the second, but it’s still a good practice to leave checks for not-null before dereferencing, in case earlier code is ever removed, or if code that modifies pos (sets it to NULL) is ever placed between these sections. (one significant disadvantage of return in the middle of a function here…)

    Other than that, there should be no difference with any optimizing compiler, but the code may convey the idea better: return blah either if *pos is NULL, or if flags are FLAGS; despite earlier condition that singles out pos==NULL, in this place of execution logic may allow it to be NULL as well and perform the return as described instead of skipping this place.

    Imagine:

     if (!*pos)
       return NULL;
    
      /* code added later here */
      if(foo) 
        pos = baz;   // added latter; baz can be NULL
      /* more code... */
    
     if (!*pos || ((*pos)->flags == FLAGS))
       return blah;
    

    This will still behave correctly, control returned if pos==NULL, only different return.

    Any change to the later condition will modify the behavior:

     if (*pos && ((*pos)->flags == FLAGS))
       return blah;
     crash();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I came across this piece of code and completely got lost interpreting its meaning.
I just came across this weird behavior today: interface IFooBar { void Foo(); void
I'm learning queues and I came across this piece of code. It's from a
I was studying some code I found on the web recently, and came across
Possible Duplicates: myVar = !!someOtherVar What does the !! operator (double exclamation point) mean
I thought that I was really starting to understand how pointers work, and then
I was reading another question on Stack Overflow ( Zen of Python ), and
Apols if this has been asked before. I am using someone else's PHP code
I was reading this excellent article which gives an introduction to Asynchronous programming here
While attempting to find a way to merge existing PDF files and forms, I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.