lexical.c, avoid to read beyond end of `string'

This commit is contained in:
rlar 2014-04-15 19:13:47 +02:00
parent f42b5b16c7
commit cb75a749b8
1 changed files with 9 additions and 7 deletions

View File

@ -107,7 +107,13 @@ pwlist_echo(wordlist *wlist, char *name)
static int
cp_readchar(char **string, FILE *fptr)
{
return (*string) ? *(*string)++ : input(fptr);
if (*string == NULL)
return input(fptr);
if (**string)
return *(*string)++;
else
return '\n';
}
@ -143,12 +149,8 @@ nloop:
c = cp_readchar(&string, cp_inp_cur);
if (string) {
if (c == '\0')
c = '\n';
if (c == ESCAPE)
c = '[';
}
if (string && (c == ESCAPE))
c = '[';
gotchar: