diff options
Diffstat (limited to 'src/bin/initdb/initdb.c')
-rw-r--r-- | src/bin/initdb/initdb.c | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c index 9994d891d1f..a0b81611276 100644 --- a/src/bin/initdb/initdb.c +++ b/src/bin/initdb/initdb.c @@ -368,6 +368,7 @@ readfile(char *path) int maxlength = 0, linelen = 0; int nlines = 0; + int n; char **result; char *buffer; int c; @@ -408,16 +409,13 @@ readfile(char *path) /* now reprocess the file and store the lines */ rewind(infile); - nlines = 0; - while (fgets(buffer, maxlength + 1, infile) != NULL) - { - result[nlines] = xstrdup(buffer); - nlines++; - } + n = 0; + while (fgets(buffer, maxlength + 1, infile) != NULL && n < nlines) + result[n++] = xstrdup(buffer); fclose(infile); free(buffer); - result[nlines] = NULL; + result[n] = NULL; return result; } |