From: sof Date: Wed, 22 Apr 1998 00:08:32 +0000 (+0000) Subject: [project @ 1998-04-22 00:08:32 by sof] X-Git-Tag: Approx_2487_patches~777 X-Git-Url: http://git.megacz.com/?a=commitdiff_plain;h=c3b3743d222e9e72dac1eb041a26a8c0cabf82d7;p=ghc-hetmet.git [project @ 1998-04-22 00:08:32 by sof] NUL terminate each dir entry name. --- diff --git a/ghc/lib/std/cbits/getDirectoryContents.lc b/ghc/lib/std/cbits/getDirectoryContents.lc index 025aae9..6f66b45 100644 --- a/ghc/lib/std/cbits/getDirectoryContents.lc +++ b/ghc/lib/std/cbits/getDirectoryContents.lc @@ -42,7 +42,6 @@ freeEntries(char **entries, int count) * operations, we collect the entire list in one atomic operation, * rather than reading the directory lazily. */ - StgAddr getDirectoryContents(path) StgByteArray path; @@ -51,7 +50,7 @@ StgByteArray path; DIR *dir; struct dirent *d; char **entries; - int alloc, count; + int alloc, count, len; /* Check for an actual directory */ while (stat(path, &sb) != 0) { @@ -100,7 +99,8 @@ StgByteArray path; } errno = 0; } - if ((entries[count] = malloc(strlen(d->d_name))) == NULL) { + len = strlen(d->d_name); + if ((entries[count] = malloc(len+1)) == NULL) { ghc_errtype = ERR_RESOURCEEXHAUSTED; ghc_errstr = "not enough virtual memory"; freeEntries(entries, count); @@ -108,6 +108,8 @@ StgByteArray path; return NULL; } strcpy(entries[count], d->d_name); + /* Terminate the sucker */ + *(entries[count] + len) = 0; if (++count == alloc) { alloc += LINK_MAX; if ((entries = (char **) realloc(entries, alloc * sizeof(char *))) == NULL) {