Skip to content

Commit

Permalink
don't return NULL on empty lines
Browse files Browse the repository at this point in the history
`grub_file_getline` returns NULL if founds an empty line.
This makes impossible to distinguish empty lines from EOF.
Let `grub_file_getline` just return an empty string in this case.

Signed-off-by: Matteo Croce <[email protected]>
  • Loading branch information
teknoraver committed Jul 20, 2024
1 parent 2b9a830 commit 398f346
Showing 1 changed file with 2 additions and 14 deletions.
16 changes: 2 additions & 14 deletions grub-core/lib/getline.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ grub_file_getline (grub_file_t file)
char c;
grub_size_t pos = 0;
char *cmdline;
int have_newline = 0;
grub_size_t max_len = 64;

/* Initially locate some space. */
Expand All @@ -57,6 +56,8 @@ grub_file_getline (grub_file_t file)
if (c == '\r')
continue;

if (c == '\n')
break;

if (pos + 1 >= max_len)
{
Expand All @@ -70,23 +71,10 @@ grub_file_getline (grub_file_t file)
}
}

if (c == '\n')
{
have_newline = 1;
break;
}

cmdline[pos++] = c;
}

cmdline[pos] = '\0';

/* If the buffer is empty, don't return anything at all. */
if (pos == 0 && !have_newline)
{
grub_free (cmdline);
cmdline = 0;
}

return cmdline;
}

0 comments on commit 398f346

Please sign in to comment.