diff options
author | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2019-11-23 17:17:54 +0100 |
---|---|---|
committer | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2019-11-23 17:17:54 +0100 |
commit | 2eaf7d3ef05047dd346dacafb268b9bc67f7ba56 (patch) | |
tree | 9bcfbe0c1bff34c21f2608e11e9650aa0ba788d1 /lib/compat/getline.c | |
parent | 687b880ddb0d67253d8903f92910a1ca3bea65ef (diff) |
Fix: add missing null-terminator in getline implementation
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/compat/getline.c')
-rw-r--r-- | lib/compat/getline.c | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/lib/compat/getline.c b/lib/compat/getline.c index f330c6d..e63c50e 100644 --- a/lib/compat/getline.c +++ b/lib/compat/getline.c @@ -43,6 +43,16 @@ ssize_t getline(char **line, size_t *n, FILE *fp) buffer[len++] = c; } while (c != '\n'); + if (len == cap) { + new = realloc(buffer, cap ? cap * 2 : 32); + if (new == NULL) + return -1; + + buffer = new; + } + + buffer[len] = '\0'; + *line = buffer; *n = len; return len; |