mirror of https://github.com/ericonr/ef.git
Fix bug in entry reading.
- deal with empty lines correctly: single letter options that don't get a newline were being missed - entirely empty lines (empty line without a newline) weren't being used correctly - fix UB from not setting line=NULL - use the delim parameter instead of hardcoding for newlines
This commit is contained in:
parent
b734660c96
commit
cbb98853d1
5
util.c
5
util.c
|
@ -9,12 +9,13 @@ void read_entries_from_stream(struct str_array *a, int delim, FILE *input)
|
|||
size_t tmp = 0;
|
||||
ssize_t n;
|
||||
while ((n = getdelim(&line, &tmp, delim, input)) >= 0) {
|
||||
if (n == 1) {
|
||||
if (n == 0 || n == 1 && line[0] == delim) {
|
||||
/* don't match empty line */
|
||||
free(line);
|
||||
line = NULL;
|
||||
continue;
|
||||
}
|
||||
if (line[n-1] == '\n') line[n-1] = 0;
|
||||
if (line[n-1] == delim) line[n-1] = '\0';
|
||||
add_entry(a, line);
|
||||
|
||||
line = NULL;
|
||||
|
|
Loading…
Reference in New Issue