Use temporary buffer in nextarg to avoid issue with strncpy under Linux.

This commit is contained in:
Renaud 2015-01-26 20:05:02 +08:00
parent fe1eaf7348
commit bc90c36603
1 changed files with 6 additions and 2 deletions

8
exec.c
View File

@ -310,16 +310,20 @@ int macarg( char *tok, int toksz)
*/ */
int nextarg(const char *prompt, char *buffer, int size, int terminator) int nextarg(const char *prompt, char *buffer, int size, int terminator)
{ {
char *tmpbuf ;
/* if we are interactive, go get it! */ /* if we are interactive, go get it! */
if (clexec == FALSE) if (clexec == FALSE)
return getstring(prompt, buffer, size, terminator); return getstring(prompt, buffer, size, terminator);
tmpbuf = malloc( size) ;
/* grab token and advance past */ /* grab token and advance past */
gettoken( buffer, size) ; gettoken( tmpbuf, size) ;
/* evaluate it */ /* evaluate it */
strncpy( buffer, getval( buffer), size - 1) ; strncpy( buffer, getval( tmpbuf), size - 1) ;
buffer[ size - 1] = '\0' ; buffer[ size - 1] = '\0' ;
free( tmpbuf) ;
return TRUE; return TRUE;
} }