c - Why does this SEGFAULT? (small amount of code) -
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include "mystuff.h" typedef struct node { int size; int status; struct node *next; struct node *previous; } node; node *endnode; node *rootnode; void *my_foo(int size) { node *thenode; void *ptr; if (rootnode->next == null) { thenode->status = 1; ...
it segfaults @ "rootnode-> == null" if change "rootnode == null" segfaults when hits "thenode->status = 1" , declaring thenode , rootnode null not help.
...and declaring thenode , rootnode
null
not help.
dereferencing null
(usually) will result in segfault. you've got set them more useful (like allocated structure) before go off modifying them!
Comments
Post a Comment