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.



int fn1(int **ar)
{
int *a = NULL; /* throws forward null. When NULL is removed, coverity throws uninit errors. */
a = *ar;
}


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.



int fn1(int **ar)
{
int *a = NULL; /* throws forward null. When NULL is removed, coverity throws uninit errors. */
a = *ar;
}


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.



int fn1(int **ar)
{
int *a = NULL; /* throws forward null. When NULL is removed, coverity throws uninit errors. */
a = *ar;
}


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.



int fn1(int **ar)
{
int *a = NULL; /* throws forward null. When NULL is removed, coverity throws uninit errors. */
a = *ar;
}


Thanks,
Preethi







c coverity






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 13 '18 at 13:26







Preethi

















asked Nov 13 '18 at 11:59









PreethiPreethi

62211




62211








  • 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














1 Answer
1






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













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

























1 Answer
1






active

oldest

votes








1 Answer
1






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,69811830




2,69811830










answered Nov 13 '18 at 12:23









Kamil CukKamil Cuk

9,9611527




9,9611527













  • 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




















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

Florida Star v. B. J. F.

Danny Elfman

Lugert, Oklahoma