Thread: Suspicious dereference of pointer

  1. #1
    Registered User
    Join Date
    Sep 2009
    Posts
    26

    Suspicious dereference of pointer

    Hi Friends

    What does this mean by this error:

    Error :"Suspicious dereference of pointer before NULL check"

    ================================================== ==
    Actually in my code snippet I have declared a pointer variable and initialized it to 1
    EX:
    unsigned int *numMatches = 1;
    // some codes
    // some codes
    ......
    .......
    if (numMatches != NULL)
    *numMatches = nRows //I got this error here only
    // some codes
    ......
    ......

    =====================================
    Please Help me out.

    Thanks in Advance
    Subhashish

  2. #2
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    could you show the real code?

    also how do you plan to check for NULL pointer if you have initialized the var to 1?
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  3. #3
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    Quote Originally Posted by subhashish1213 View Post
    Error :"Suspicious dereference of pointer before NULL check"
    Is this being generated by a static analysis tool or the compiler? Which one?

    Also, it's illegal to initialize a pointer to any literal constant other than 0. So I'm guessing this is not a compiler you are using.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  4. #4
    Registered User
    Join Date
    Sep 2009
    Posts
    26

    Suspicious dereference of pointer before NULL check

    Its being generated by a memory profiling tool ..."klockwork"

    Thanks in Advance!!!

  5. #5
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Ah, but don't ignore it! Figure out why it's saying that. It might be a good reason and not using it will probably turn up bugs elsewhere.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #6
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    First try to compile your code. Currently it doesn't. No point in running such tools if your code doesn't even compile.

    As for the error itself, no code analysis tool worth its salt will flag "Suspicious dereference of pointer before NULL check" on the second line of the following snippet:

    Code:
    if (numMatches != NULL)
    *numMatches = nRows //I got this error here only
    Only exception is if NULL is being defined as something else. But being the case youcan't even compile your code, it's rather mute at this point to try and interpret the results of a code analysis tool.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 0
    Last Post: 03-20-2008, 07:59 AM
  2. How did you master pointers?
    By Afrinux in forum C Programming
    Replies: 15
    Last Post: 01-17-2006, 08:23 PM
  3. scope of a pointer?
    By Syneris in forum C++ Programming
    Replies: 6
    Last Post: 12-29-2005, 09:40 PM
  4. Could somebody please help me with this C program
    By brett73 in forum C Programming
    Replies: 6
    Last Post: 11-25-2004, 02:19 AM
  5. Struct *** initialization
    By Saravanan in forum C Programming
    Replies: 20
    Last Post: 10-09-2003, 12:04 PM