Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clang reports an issue at slist.c:744 #29

Closed
f2404 opened this issue Apr 5, 2016 · 2 comments
Closed

clang reports an issue at slist.c:744 #29

f2404 opened this issue Apr 5, 2016 · 2 comments

Comments

@f2404
Copy link
Contributor

f2404 commented Apr 5, 2016

slist.c:744:20: warning: Access to field 'next' results in a dereference of a null pointer (loaded from variable 'flip')
        flip->next = prev;
        ~~~~       ^

The questionable code is at https://github.com/srdja/Collections-C/blob/master/src/slist.c#L747

    for (i = 0; i < list->size; i++) {
        flip->next = prev;

        prev = flip;
        flip = next;
        next = next ? next->next : NULL;
    }

As I understand it, clang is worried about the condition to break the loop: on one hand, list size is used a list iterator; on the other hand, next element is verified against NULL on each cycle - which could mean that the size is not still exhausted but next element is NULL.

Maybe it's worth to change the loop to iterate by list->next to make it more clear?

@f2404 f2404 changed the title clang reports an issue at slang.c:744 clang reports an issue at slist.c:744 Apr 5, 2016
@srdja
Copy link
Owner

srdja commented Apr 6, 2016

I have added a fix for this as you suggested. It shouldn't raise the warning now.

@f2404
Copy link
Contributor Author

f2404 commented Apr 6, 2016

Yep, clang is glad now!

@f2404 f2404 closed this as completed Apr 6, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants