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 6598705
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:23:15+00:00 2026-05-25T18:23:15+00:00

I have the following example code and would like to know what kind of

  • 0

I have the following example code and would like to know what kind of annotations I can use to avoid them.

int Function(classA* pInput) {
   if (pInput == NULL) {
      classA::Create(pInput);
   }

   return pInput->value;
}

The problem is that since Prefast evaluates only the function it doesn’t know that Create initializes the pointer.

I thought I could solve it by using the __out annotation in the header file for classA::Create however that didn’t work.

I’m wondering if there is a good alternative to just __analysis_assume everywhere in the code such that prefast picks it up from the function definition.

Secondly,
I was wondering how would I set up my build configuration so that I can build my code natively on Linux or with GCC with these preprocessor directives. Would I have to check if it’s on a LINUX build and then add those annotations as empty Macros?

  • 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-25T18:23:16+00:00Added an answer on May 25, 2026 at 6:23 pm

    MSalter’s answer sounds very much like the correct technical answer. Happily I don’t know SAL so I can’t say for sure, but it looks like the technical level solution.

    However, I would just recommend that you rewrite your current code …

    int Function(classA* pInput) {
       if (pInput == NULL) {
          classA::Create(pInput);
       }
    
       return pInput->value;
    }
    

    as …

    int Function( classA* pInput ) {
       if (pInput == NULL) {
          pInput = classA::Create();
       }
    
       return pInput->value;
    }
    

    The main issue here is whether you’re leaking a dynamically created object, or not. That depends very much on what the Create method does. But it does look like you’re leaking.

    And in that case, where Create does nothing but dynamically allocate a default-initialized classA object, then here is how you can do that more safely and more efficiently:

    int Function( classA* pInput ) {
       if (pInput == NULL) {
          return classA().value;
       }
    
       return pInput->value;
    }
    

    Finally, for a total clean-up consider how to get rid of unnecessary raw pointers. Because raw pointers create problems (your code being just a very small example of that). Then you can do things like this:

    int function( ClassA const& anObject = ClassA() )
    {
       return anObject.value;
    }
    

    Essentially this is a C++ level solution, as opposed to the original code’s C level. So I changed also the naming convention to reflect the much stronger focus on types at the C++ level. Here the types have uppercase first letter, and a mere function has lowercase first letter.

    It’s simpler, it’s safer, it’s again more efficient.

    And – at the C++ level you generally don’t have to struggle with silly SAL notations. 🙂

    Cheers & hth.,

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to know how to the following: I have 2 foreach loops,
How can i achieve that I get jQuery-Intellisense in the following code example? function
I have the following example code: class A(object): def __init__(self, id): self.myid = id
Say suppose I have the following Java code. public class Example { public static
Say I have the following code: <div onclick='location.href=http://www.example.com/'> <a href='#' onclick='alert(blah)'>click</a> </div> Is there
On a report I have the following code for a field: =Sum([PartQty]*[ModuleQty]) Example results
I have the following example, compiled in VS2005, warning level 4: int main(int argc,
I would like to compile c# source code from a string. I know this
In my example code below, you can see that I have been trying to
i would like to know if there is a possible injection of code (or

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.