Replace mlreply by newmlarg in eval, allowing user variable length to exceed 255 bytes.

This commit is contained in:
Renaud 2015-09-29 11:43:30 +08:00
parent 7f5f0dd7b3
commit f13ae3957c
2 changed files with 17 additions and 13 deletions

26
eval.c
View File

@ -769,7 +769,7 @@ int setvar(int f, int n)
int status; /* status return */ int status; /* status return */
struct variable_description vd; /* variable num/type */ struct variable_description vd; /* variable num/type */
char var[NVSIZE + 2]; /* name of variable to fetch %1234567890\0 */ char var[NVSIZE + 2]; /* name of variable to fetch %1234567890\0 */
char value[ 2 * NSTRING] ; /* value to set variable to */ char *value ; /* value to set variable to */
/* first get the variable to set.. */ /* first get the variable to set.. */
if (clexec == FALSE) { if (clexec == FALSE) {
@ -792,11 +792,15 @@ int setvar(int f, int n)
/* get the value for that variable */ /* get the value for that variable */
if( f == TRUE) { if( f == TRUE) {
value = malloc( NSTRING) ;
if( value == NULL)
return FALSE ;
/* a bit overcautious here in using strncpy */ /* a bit overcautious here in using strncpy */
strncpy( value, i_to_a( n), sizeof value - 1) ; strncpy( value, i_to_a( n), NSTRING - 1) ;
value[ sizeof value - 1] = '\0' ; value[ NSTRING - 1] = '\0' ;
} else { } else {
status = mlreply( "Value: ", value, sizeof value); status = newmlarg( &value, "Value: ", 0) ;
if (status != TRUE) if (status != TRUE)
return status; return status;
} }
@ -814,6 +818,7 @@ int setvar(int f, int n)
#endif #endif
/* and return it */ /* and return it */
free( value) ;
return status; return status;
} }
@ -1430,20 +1435,15 @@ int clrmes( int f, int n) {
*/ */
int writemsg( int f, int n) { int writemsg( int f, int n) {
int status ; int status ;
int size ;
char *buf ; /* buffer to receive message into */ char *buf ; /* buffer to receive message into */
size = term.t_ncol + 1 ; status = newmlarg( &buf, "Message to write: ", 0) ;
buf = malloc( size) ; if( status == TRUE) {
if( buf == NULL)
return FALSE ;
status = mlreply( "Message to write: ", buf, size) ;
if( status == TRUE)
/* write the message out */ /* write the message out */
mlforce( buf) ; mlforce( buf) ;
free( buf) ;
}
free( buf) ;
return status ; return status ;
} }

View File

@ -10,6 +10,7 @@ insert-string %mypath
newline newline
insert-string &cat "Length of $PATH: " &len $PATH insert-string &cat "Length of $PATH: " &len $PATH
newline newline
insert-string &cat "Length of %mypath: " &cat &len %mypath ~n
; Insert string with escaped characters ; Insert string with escaped characters
insert-string "hello, world~n" insert-string "hello, world~n"
newline newline
@ -35,6 +36,9 @@ set %expect &len %nam
newline newline
set %nam &cat %nam %nam set %nam &cat %nam %nam
set %expect &tim %expect 2 set %expect &tim %expect 2
!if &not &les %expect 1024
!break
!endif
!endwhile !endwhile
insert-string %nam insert-string %nam
newline newline