提交 dae17a1a 编写于 作者: R Rich Felker

fix errno handling in scandir:

1. saved errno was not being restored, illegally clearing errno to 0.
2. no need to backup and save errno around free; it will not touch
except perhaps when the program has already invoked UB...
上级 52458cfa
...@@ -35,12 +35,11 @@ int scandir(const char *path, struct dirent ***res, ...@@ -35,12 +35,11 @@ int scandir(const char *path, struct dirent ***res,
closedir(d); closedir(d);
if (errno) { if (errno) {
old_errno = errno;
if (names) while (cnt-->0) free(names[cnt]); if (names) while (cnt-->0) free(names[cnt]);
free(names); free(names);
errno = old_errno;
return -1; return -1;
} }
errno = old_errno;
if (cmp) qsort(names, cnt, sizeof *names, (int (*)(const void *, const void *))cmp); if (cmp) qsort(names, cnt, sizeof *names, (int (*)(const void *, const void *))cmp);
*res = names; *res = names;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册