【发布时间】:2020-02-06 02:33:43
【问题描述】:
由于此代码,我遇到了分段错误(核心转储)错误:
char **getPipedCmds(Pgm *p){
if (p == NULL) {
} else {
char **pipedP = p->next->pgmlist; // I'm the line where the seg fault occurs.
return pipedP;
}
}
这里是结构定义,在这里可能非常有用......
typedef struct c {
char **pgmlist;
struct c *next;
} Pgm;
typedef struct node {
Pgm *pgm;
...
} Command;
那么,有没有办法从p->next->pgmlist 获取我需要的数据而不会出现段错误?
【问题讨论】:
-
好吧 p->next 为空或指向任何地方
-
你已经确定了
p != NULL,但是p->next != NULL呢?在取消引用之前,您应该始终知道指针是否为NULL。 -
并非所有控制路径都返回值。
标签: c shell syntax segmentation-fault