X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fuci.git;a=blobdiff_plain;f=file.c;h=5a8c6cb51bb143fe23c5e272cc0a0805ff17b0fa;hp=7e1e4e6f0ddcdbb545c4e83efda52fb33031374a;hb=49ec6efbdac4819033d34f08927d795f83a3932d;hpb=c203c2f9009a322e5e774ff8cd32bac2fa3b7961 diff --git a/file.c b/file.c index 7e1e4e6..5a8c6cb 100644 --- a/file.c +++ b/file.c @@ -835,7 +835,7 @@ static char **uci_list_config_files(struct uci_context *ctx) { char **configs; glob_t globbuf; - int size, i; + int size, i, j, skipped; char *buf; char *dir; @@ -847,18 +847,22 @@ static char **uci_list_config_files(struct uci_context *ctx) } size = sizeof(char *) * (globbuf.gl_pathc + 1); + skipped = 0; for(i = 0; i < globbuf.gl_pathc; i++) { char *p; p = get_filename(globbuf.gl_pathv[i]); - if (!p) + if (!p) { + skipped++; continue; + } size += strlen(p) + 1; } - configs = uci_malloc(ctx, size); - buf = (char *) &configs[globbuf.gl_pathc + 1]; + configs = uci_malloc(ctx, size - skipped); + buf = (char *) &configs[globbuf.gl_pathc + 1 - skipped]; + j = 0; for(i = 0; i < globbuf.gl_pathc; i++) { char *p; @@ -869,7 +873,7 @@ static char **uci_list_config_files(struct uci_context *ctx) if (!uci_validate_package(p)) continue; - configs[i] = buf; + configs[j++] = buf; strcpy(buf, p); buf += strlen(buf) + 1; }