Suspicious dereference of pointer

This is a discussion on Suspicious dereference of pointer within the C++ Programming forums, part of the General Programming Boards category; Hi Friends What does this mean by this error: Error :"Suspicious dereference of pointer before NULL check" ================================================== == Actually ...

  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
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,454
    could you show the real code?

    also how do you plan to check for NULL pointer if you have initialized the var to 1?
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  3. #3
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,403
    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.
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    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をこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,411
    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
    Portugal
    Posts
    7,403
    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.
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    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, 07:23 PM
  3. scope of a pointer?
    By Syneris in forum C++ Programming
    Replies: 6
    Last Post: 12-29-2005, 08: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, 01:19 AM
  5. Struct *** initialization
    By Saravanan in forum C Programming
    Replies: 20
    Last Post: 10-09-2003, 12:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21