summaryrefslogtreecommitdiff
path: root/src/bin/initdb/initdb.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/bin/initdb/initdb.c')
-rw-r--r--src/bin/initdb/initdb.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c
index d5101fad2fc..f3e1d90dc41 100644
--- a/src/bin/initdb/initdb.c
+++ b/src/bin/initdb/initdb.c
@@ -368,6 +368,7 @@ readfile(const char *path)
int maxlength = 1,
linelen = 0;
int nlines = 0;
+ int n;
char **result;
char *buffer;
int c;
@@ -405,13 +406,13 @@ readfile(const 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);
+ 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;
}