FORWARD_NULL Vs UNINIT Coverity errors in C












0















when a pointer is initialized to NULL, getting "FORWARD_NULL" coverity errors and when the NULL initialization is removed, it throws UNINIT coverity errors. The code is as below.



I am very new to coverity. If its a very basic question also, please help.



I am



1) declaring a pointer,



2) Initializing it to NULL and



3) deferring it without assigning anything to it.



This deference is an argument in a function call inside which, it will be filled in. Getting FORWARD_NULL errors for the same. Started with Coverity works, from yesterday only.



int fn1()
{
strct1 *pvarA = NULL;
if (fn2(&pvarA) != 0) // derefering NULL pointer error.
{
return 1;
}
...
/* some code */
}

int fn2(strct1 **pvarA)
{
...
/* some code */
*pvarA = varA;
/* some code */
return 0;
}


Thanks,
Preethi










share|improve this question




















  • 1





    How exactly does this code makes sense to you? As for why it complains if you drop the NULL, we cannot say without a Minimal, Complete, and Verifiable example. It could also be a tool bug, but none can tell with what's given here.

    – Lundin
    Nov 13 '18 at 12:04






  • 1





    FORWARD_NULL implies that you're dereferencing the NULL, but that's not what your code shows.

    – Sander De Dycker
    Nov 13 '18 at 12:21











  • Your code doesn't match your question. Did you mean *a = **ar?

    – Jabberwocky
    Nov 13 '18 at 12:29











  • Nope. It is matching. @Jabberwocky I wanted to do a = *ar. But in the line int *a = NULL, getting coverity error as mentioned in the comments /* */

    – Preethi
    Nov 13 '18 at 13:32


















0















when a pointer is initialized to NULL, getting "FORWARD_NULL" coverity errors and when the NULL initialization is removed, it throws UNINIT coverity errors. The code is as below.



I am very new to coverity. If its a very basic question also, please help.



I am



1) declaring a pointer,



2) Initializing it to NULL and



3) deferring it without assigning anything to it.



This deference is an argument in a function call inside which, it will be filled in. Getting FORWARD_NULL errors for the same. Started with Coverity works, from yesterday only.



int fn1()
{
strct1 *pvarA = NULL;
if (fn2(&pvarA) != 0) // derefering NULL pointer error.
{
return 1;
}
...
/* some code */
}

int fn2(strct1 **pvarA)
{
...
/* some code */
*pvarA = varA;
/* some code */
return 0;
}


Thanks,
Preethi










share|improve this question




















  • 1





    How exactly does this code makes sense to you? As for why it complains if you drop the NULL, we cannot say without a Minimal, Complete, and Verifiable example. It could also be a tool bug, but none can tell with what's given here.

    – Lundin
    Nov 13 '18 at 12:04






  • 1





    FORWARD_NULL implies that you're dereferencing the NULL, but that's not what your code shows.

    – Sander De Dycker
    Nov 13 '18 at 12:21











  • Your code doesn't match your question. Did you mean *a = **ar?

    – Jabberwocky
    Nov 13 '18 at 12:29











  • Nope. It is matching. @Jabberwocky I wanted to do a = *ar. But in the line int *a = NULL, getting coverity error as mentioned in the comments /* */

    – Preethi
    Nov 13 '18 at 13:32
















0












0








0








when a pointer is initialized to NULL, getting "FORWARD_NULL" coverity errors and when the NULL initialization is removed, it throws UNINIT coverity errors. The code is as below.



I am very new to coverity. If its a very basic question also, please help.



I am



1) declaring a pointer,



2) Initializing it to NULL and



3) deferring it without assigning anything to it.



This deference is an argument in a function call inside which, it will be filled in. Getting FORWARD_NULL errors for the same. Started with Coverity works, from yesterday only.



int fn1()
{
strct1 *pvarA = NULL;
if (fn2(&pvarA) != 0) // derefering NULL pointer error.
{
return 1;
}
...
/* some code */
}

int fn2(strct1 **pvarA)
{
...
/* some code */
*pvarA = varA;
/* some code */
return 0;
}


Thanks,
Preethi










share|improve this question
















when a pointer is initialized to NULL, getting "FORWARD_NULL" coverity errors and when the NULL initialization is removed, it throws UNINIT coverity errors. The code is as below.



I am very new to coverity. If its a very basic question also, please help.



I am



1) declaring a pointer,



2) Initializing it to NULL and



3) deferring it without assigning anything to it.



This deference is an argument in a function call inside which, it will be filled in. Getting FORWARD_NULL errors for the same. Started with Coverity works, from yesterday only.



int fn1()
{
strct1 *pvarA = NULL;
if (fn2(&pvarA) != 0) // derefering NULL pointer error.
{
return 1;
}
...
/* some code */
}

int fn2(strct1 **pvarA)
{
...
/* some code */
*pvarA = varA;
/* some code */
return 0;
}


Thanks,
Preethi







c coverity






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 24 at 14:28







Preethi

















asked Nov 13 '18 at 11:59









PreethiPreethi

67211




67211








  • 1





    How exactly does this code makes sense to you? As for why it complains if you drop the NULL, we cannot say without a Minimal, Complete, and Verifiable example. It could also be a tool bug, but none can tell with what's given here.

    – Lundin
    Nov 13 '18 at 12:04






  • 1





    FORWARD_NULL implies that you're dereferencing the NULL, but that's not what your code shows.

    – Sander De Dycker
    Nov 13 '18 at 12:21











  • Your code doesn't match your question. Did you mean *a = **ar?

    – Jabberwocky
    Nov 13 '18 at 12:29











  • Nope. It is matching. @Jabberwocky I wanted to do a = *ar. But in the line int *a = NULL, getting coverity error as mentioned in the comments /* */

    – Preethi
    Nov 13 '18 at 13:32
















  • 1





    How exactly does this code makes sense to you? As for why it complains if you drop the NULL, we cannot say without a Minimal, Complete, and Verifiable example. It could also be a tool bug, but none can tell with what's given here.

    – Lundin
    Nov 13 '18 at 12:04






  • 1





    FORWARD_NULL implies that you're dereferencing the NULL, but that's not what your code shows.

    – Sander De Dycker
    Nov 13 '18 at 12:21











  • Your code doesn't match your question. Did you mean *a = **ar?

    – Jabberwocky
    Nov 13 '18 at 12:29











  • Nope. It is matching. @Jabberwocky I wanted to do a = *ar. But in the line int *a = NULL, getting coverity error as mentioned in the comments /* */

    – Preethi
    Nov 13 '18 at 13:32










1




1





How exactly does this code makes sense to you? As for why it complains if you drop the NULL, we cannot say without a Minimal, Complete, and Verifiable example. It could also be a tool bug, but none can tell with what's given here.

– Lundin
Nov 13 '18 at 12:04





How exactly does this code makes sense to you? As for why it complains if you drop the NULL, we cannot say without a Minimal, Complete, and Verifiable example. It could also be a tool bug, but none can tell with what's given here.

– Lundin
Nov 13 '18 at 12:04




1




1





FORWARD_NULL implies that you're dereferencing the NULL, but that's not what your code shows.

– Sander De Dycker
Nov 13 '18 at 12:21





FORWARD_NULL implies that you're dereferencing the NULL, but that's not what your code shows.

– Sander De Dycker
Nov 13 '18 at 12:21













Your code doesn't match your question. Did you mean *a = **ar?

– Jabberwocky
Nov 13 '18 at 12:29





Your code doesn't match your question. Did you mean *a = **ar?

– Jabberwocky
Nov 13 '18 at 12:29













Nope. It is matching. @Jabberwocky I wanted to do a = *ar. But in the line int *a = NULL, getting coverity error as mentioned in the comments /* */

– Preethi
Nov 13 '18 at 13:32







Nope. It is matching. @Jabberwocky I wanted to do a = *ar. But in the line int *a = NULL, getting coverity error as mentioned in the comments /* */

– Preethi
Nov 13 '18 at 13:32














2 Answers
2






active

oldest

votes


















2














In such code:



int fn1(int **ar)
{
int *a;
a = *ar;
}


The variable a is not initialized (thus UNINIT) and the variable ar is dereferenced without checking for null (thus FORWARD_NULL).



Probably this code will work:



#include <stddef.h>
#include <stdlib.h>
#include <stdio.h>

int fn1(int **ar)
{
int *a = NULL;
if (ar == NULL) {
fprintf(stderr, "Omg! you passed NULL as first argument to fn1 function. What to do now? Break the program flow for sure - return or abort() or exit() !");
abort();
return EXIT_FAILURE;
}
a = *ar;
return EXIT_SUCCESS;
}





share|improve this answer


























  • Thanks a lot. Trying it out. Once it is going to work, will update this as answer.

    – Preethi
    Nov 13 '18 at 13:07











  • I did this: int fn1(int **ar) { int *a = NULL; /* throws forward null, when NULL is removed, coverity throws unint errors. */ if (ar == NULL) { return 1;} a = *ar; } My coverity error still exists. @kamil

    – Preethi
    Nov 13 '18 at 13:24





















0














This helps easily:



#include<stdio.h>
#include<string.h>
#include<stdlib.h>

strct1
{
int a;
int b;
char c;
};

int fn1()
{
strct1 *pvarA = NULL;
strct1 varA;

MEMSET(&varA, 0, sizeof (strct1));
pvarA = &varA;
if (fn2(&pvarA) != 0) // derefering NULL pointer error.
{
return 1;
}
/* some code */
}

int fn2(strct1 **pvarA)
{
/* some code */
*pvarA = varA;
/* some code */
return 0;
}





share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53280581%2fforward-null-vs-uninit-coverity-errors-in-c%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2














    In such code:



    int fn1(int **ar)
    {
    int *a;
    a = *ar;
    }


    The variable a is not initialized (thus UNINIT) and the variable ar is dereferenced without checking for null (thus FORWARD_NULL).



    Probably this code will work:



    #include <stddef.h>
    #include <stdlib.h>
    #include <stdio.h>

    int fn1(int **ar)
    {
    int *a = NULL;
    if (ar == NULL) {
    fprintf(stderr, "Omg! you passed NULL as first argument to fn1 function. What to do now? Break the program flow for sure - return or abort() or exit() !");
    abort();
    return EXIT_FAILURE;
    }
    a = *ar;
    return EXIT_SUCCESS;
    }





    share|improve this answer


























    • Thanks a lot. Trying it out. Once it is going to work, will update this as answer.

      – Preethi
      Nov 13 '18 at 13:07











    • I did this: int fn1(int **ar) { int *a = NULL; /* throws forward null, when NULL is removed, coverity throws unint errors. */ if (ar == NULL) { return 1;} a = *ar; } My coverity error still exists. @kamil

      – Preethi
      Nov 13 '18 at 13:24


















    2














    In such code:



    int fn1(int **ar)
    {
    int *a;
    a = *ar;
    }


    The variable a is not initialized (thus UNINIT) and the variable ar is dereferenced without checking for null (thus FORWARD_NULL).



    Probably this code will work:



    #include <stddef.h>
    #include <stdlib.h>
    #include <stdio.h>

    int fn1(int **ar)
    {
    int *a = NULL;
    if (ar == NULL) {
    fprintf(stderr, "Omg! you passed NULL as first argument to fn1 function. What to do now? Break the program flow for sure - return or abort() or exit() !");
    abort();
    return EXIT_FAILURE;
    }
    a = *ar;
    return EXIT_SUCCESS;
    }





    share|improve this answer


























    • Thanks a lot. Trying it out. Once it is going to work, will update this as answer.

      – Preethi
      Nov 13 '18 at 13:07











    • I did this: int fn1(int **ar) { int *a = NULL; /* throws forward null, when NULL is removed, coverity throws unint errors. */ if (ar == NULL) { return 1;} a = *ar; } My coverity error still exists. @kamil

      – Preethi
      Nov 13 '18 at 13:24
















    2












    2








    2







    In such code:



    int fn1(int **ar)
    {
    int *a;
    a = *ar;
    }


    The variable a is not initialized (thus UNINIT) and the variable ar is dereferenced without checking for null (thus FORWARD_NULL).



    Probably this code will work:



    #include <stddef.h>
    #include <stdlib.h>
    #include <stdio.h>

    int fn1(int **ar)
    {
    int *a = NULL;
    if (ar == NULL) {
    fprintf(stderr, "Omg! you passed NULL as first argument to fn1 function. What to do now? Break the program flow for sure - return or abort() or exit() !");
    abort();
    return EXIT_FAILURE;
    }
    a = *ar;
    return EXIT_SUCCESS;
    }





    share|improve this answer















    In such code:



    int fn1(int **ar)
    {
    int *a;
    a = *ar;
    }


    The variable a is not initialized (thus UNINIT) and the variable ar is dereferenced without checking for null (thus FORWARD_NULL).



    Probably this code will work:



    #include <stddef.h>
    #include <stdlib.h>
    #include <stdio.h>

    int fn1(int **ar)
    {
    int *a = NULL;
    if (ar == NULL) {
    fprintf(stderr, "Omg! you passed NULL as first argument to fn1 function. What to do now? Break the program flow for sure - return or abort() or exit() !");
    abort();
    return EXIT_FAILURE;
    }
    a = *ar;
    return EXIT_SUCCESS;
    }






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Jan 10 at 16:47









    Paul Floyd

    2,70811830




    2,70811830










    answered Nov 13 '18 at 12:23









    Kamil CukKamil Cuk

    10.3k1527




    10.3k1527













    • Thanks a lot. Trying it out. Once it is going to work, will update this as answer.

      – Preethi
      Nov 13 '18 at 13:07











    • I did this: int fn1(int **ar) { int *a = NULL; /* throws forward null, when NULL is removed, coverity throws unint errors. */ if (ar == NULL) { return 1;} a = *ar; } My coverity error still exists. @kamil

      – Preethi
      Nov 13 '18 at 13:24





















    • Thanks a lot. Trying it out. Once it is going to work, will update this as answer.

      – Preethi
      Nov 13 '18 at 13:07











    • I did this: int fn1(int **ar) { int *a = NULL; /* throws forward null, when NULL is removed, coverity throws unint errors. */ if (ar == NULL) { return 1;} a = *ar; } My coverity error still exists. @kamil

      – Preethi
      Nov 13 '18 at 13:24



















    Thanks a lot. Trying it out. Once it is going to work, will update this as answer.

    – Preethi
    Nov 13 '18 at 13:07





    Thanks a lot. Trying it out. Once it is going to work, will update this as answer.

    – Preethi
    Nov 13 '18 at 13:07













    I did this: int fn1(int **ar) { int *a = NULL; /* throws forward null, when NULL is removed, coverity throws unint errors. */ if (ar == NULL) { return 1;} a = *ar; } My coverity error still exists. @kamil

    – Preethi
    Nov 13 '18 at 13:24







    I did this: int fn1(int **ar) { int *a = NULL; /* throws forward null, when NULL is removed, coverity throws unint errors. */ if (ar == NULL) { return 1;} a = *ar; } My coverity error still exists. @kamil

    – Preethi
    Nov 13 '18 at 13:24















    0














    This helps easily:



    #include<stdio.h>
    #include<string.h>
    #include<stdlib.h>

    strct1
    {
    int a;
    int b;
    char c;
    };

    int fn1()
    {
    strct1 *pvarA = NULL;
    strct1 varA;

    MEMSET(&varA, 0, sizeof (strct1));
    pvarA = &varA;
    if (fn2(&pvarA) != 0) // derefering NULL pointer error.
    {
    return 1;
    }
    /* some code */
    }

    int fn2(strct1 **pvarA)
    {
    /* some code */
    *pvarA = varA;
    /* some code */
    return 0;
    }





    share|improve this answer




























      0














      This helps easily:



      #include<stdio.h>
      #include<string.h>
      #include<stdlib.h>

      strct1
      {
      int a;
      int b;
      char c;
      };

      int fn1()
      {
      strct1 *pvarA = NULL;
      strct1 varA;

      MEMSET(&varA, 0, sizeof (strct1));
      pvarA = &varA;
      if (fn2(&pvarA) != 0) // derefering NULL pointer error.
      {
      return 1;
      }
      /* some code */
      }

      int fn2(strct1 **pvarA)
      {
      /* some code */
      *pvarA = varA;
      /* some code */
      return 0;
      }





      share|improve this answer


























        0












        0








        0







        This helps easily:



        #include<stdio.h>
        #include<string.h>
        #include<stdlib.h>

        strct1
        {
        int a;
        int b;
        char c;
        };

        int fn1()
        {
        strct1 *pvarA = NULL;
        strct1 varA;

        MEMSET(&varA, 0, sizeof (strct1));
        pvarA = &varA;
        if (fn2(&pvarA) != 0) // derefering NULL pointer error.
        {
        return 1;
        }
        /* some code */
        }

        int fn2(strct1 **pvarA)
        {
        /* some code */
        *pvarA = varA;
        /* some code */
        return 0;
        }





        share|improve this answer













        This helps easily:



        #include<stdio.h>
        #include<string.h>
        #include<stdlib.h>

        strct1
        {
        int a;
        int b;
        char c;
        };

        int fn1()
        {
        strct1 *pvarA = NULL;
        strct1 varA;

        MEMSET(&varA, 0, sizeof (strct1));
        pvarA = &varA;
        if (fn2(&pvarA) != 0) // derefering NULL pointer error.
        {
        return 1;
        }
        /* some code */
        }

        int fn2(strct1 **pvarA)
        {
        /* some code */
        *pvarA = varA;
        /* some code */
        return 0;
        }






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jan 24 at 14:53









        PreethiPreethi

        67211




        67211






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53280581%2fforward-null-vs-uninit-coverity-errors-in-c%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Full-time equivalent

            Bicuculline

            さくらももこ