The control flow in scandir() (only used on Windows) confuses gcc into
thinking that *name_list is not always set on success, which causes a
-Wmaybe-uninitialized warning in __populate_fs(). As far as I can tell
it's a false positive; however, avoid it by cleanly separating the
success and failure cases in scandir().
Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
size_t new_list_size = temp_list_size + 32;
struct dirent **new_list = (struct dirent**)realloc(
temp_list, new_list_size * sizeof(struct dirent*));
size_t new_list_size = temp_list_size + 32;
struct dirent **new_list = (struct dirent**)realloc(
temp_list, new_list_size * sizeof(struct dirent*));
- if (new_list == NULL) {
- goto out;
- }
+ if (new_list == NULL)
+ goto out_err;
temp_list_size = new_list_size;
temp_list = new_list;
}
// add the copy of dirent to the list
temp_list[num_dent] = (struct dirent*)malloc((dent->d_reclen + 3) & ~3);
if (!temp_list[num_dent])
temp_list_size = new_list_size;
temp_list = new_list;
}
// add the copy of dirent to the list
temp_list[num_dent] = (struct dirent*)malloc((dent->d_reclen + 3) & ~3);
if (!temp_list[num_dent])
memcpy(temp_list[num_dent], dent, dent->d_reclen);
num_dent++;
}
memcpy(temp_list[num_dent], dent, dent->d_reclen);
num_dent++;
}
if (compar != NULL) {
qsort(temp_list, num_dent, sizeof(struct dirent*),
(int (*)(const void*, const void*))compar);
}
if (compar != NULL) {
qsort(temp_list, num_dent, sizeof(struct dirent*),
(int (*)(const void*, const void*))compar);
}
-
- // release the temp list
-out:
- if (temp_list != NULL) {
- while (num_dent > 0) {
- free(temp_list[--num_dent]);
- }
- free(temp_list);
- num_dent = -1;
- }
+ while (num_dent > 0)
+ free(temp_list[--num_dent]);
+ free(temp_list);
+ return -1;
}
static int alphasort(const struct dirent **a, const struct dirent **b) {
}
static int alphasort(const struct dirent **a, const struct dirent **b) {