1
0
mirror of https://github.com/rfivet/uemacs.git synced 2024-12-18 15:26:23 -05:00

Insure &low and &upp don't point to the stack.

This commit is contained in:
Renaud 2015-01-09 09:46:03 +08:00
parent 4070a97fc9
commit 57e5338ebd
2 changed files with 21 additions and 5 deletions

25
eval.c
View File

@ -66,6 +66,7 @@ static char errorm[] = "ERROR" ; /* error literal */
static int seed = 0 ; /* random number seed */ static int seed = 0 ; /* random number seed */
static char *ltos( int val) ; static char *ltos( int val) ;
static char *mkupper( char *str) ;
/* List of recognized environment variables. */ /* List of recognized environment variables. */
@ -396,7 +397,7 @@ char *gtfun(char *fname)
} }
strcpy( result, arg1) ; strcpy( result, arg1) ;
strcat( &result[ sz1], argx) ; strcpy( &result[ sz1], argx) ;
retstr = result ; retstr = result ;
} }
break ; break ;
@ -468,10 +469,26 @@ char *gtfun(char *fname)
retstr = i_to_a( strlen( argx)) ; retstr = i_to_a( strlen( argx)) ;
break ; break ;
case UFUPPER: case UFUPPER:
retstr = mkupper( argx) ; sz = strlen( argx) ;
if( sz >= ressize) {
free( result) ;
result = malloc( sz + 1) ;
ressize = sz + 1 ;
}
strcpy( result, argx) ; /* result is at least as long as argx */
retstr = mkupper( result) ;
break ; break ;
case UFLOWER: case UFLOWER:
retstr = mklower( argx) ; sz = strlen( argx) ;
if( sz >= ressize) {
free( result) ;
result = malloc( sz + 1) ;
ressize = sz + 1 ;
}
strcpy( result, argx) ; /* result is at least as long as argx */
retstr = mklower( result) ;
break ; break ;
case UFTRUTH: case UFTRUTH:
retstr = ltos( atoi( argx) == 42) ; retstr = ltos( atoi( argx) == 42) ;
@ -1240,7 +1257,7 @@ static char *ltos( int val)
* *
* char *str; string to upper case * char *str; string to upper case
*/ */
char *mkupper(char *str) static char *mkupper( char *str)
{ {
char *sp; char *sp;

1
eval.h
View File

@ -46,7 +46,6 @@ int setvar( int f, int n) ;
char *i_to_a( int i) ; char *i_to_a( int i) ;
char *getval( char *token) ; char *getval( char *token) ;
int stol( char *val) ; int stol( char *val) ;
char *mkupper( char *str) ;
char *mklower( char *str) ; char *mklower( char *str) ;
int abs( int x) ; int abs( int x) ;
int ernd( void) ; int ernd( void) ;