使用FTS fts_open()时strlen中的分段错误

时间:2013-03-06 04:30:18

标签: c arrays segmentation-fault traversal strlen

我有一个我发现的错误归结为:

#include <sys/types.h>
#include <sys/stat.h>
#include <fts.h>
#include <stdlib.h>

int main () {
    char *LOG_ROOT = "/var/log";

    FTS *ftsp; 
    FTSENT *p, *chp;
    int fts_options = FTS_COMFOLLOW | FTS_LOGICAL | FTS_NOCHDIR;

    char *paths[] = { LOG_ROOT };
    fts_open(paths, fts_options, NULL);
}

为什么会出现这种错误?

1 个答案:

答案 0 :(得分:2)

第一个arg。应该是一个 NULL终止数组的字符指针。

char *paths[] = { LOG_ROOT, NULL};