1
0
mirror of https://github.com/rfivet/uemacs.git synced 2024-12-19 15:56:24 -05:00

Redimension result char array when doing &lef, &mid, &rig.

This commit is contained in:
Renaud 2015-01-07 14:47:13 +08:00
parent 5756354dd5
commit d2d3581e74

31
eval.c
View File

@ -384,21 +384,38 @@ char *gtfun(char *fname)
int sz ; int sz ;
sz = atoi( arg2) ; sz = atoi( arg2) ;
if( sz >= ressize) if( sz >= ressize) {
sz = ressize - 1 ; free( result) ;
result = malloc( sz + 1) ;
ressize = sz + 1 ;
}
strncpy( result, arg1, sz) ; strncpy( result, arg1, sz) ;
result[ sz] = 0 ; result[ sz] = 0 ;
return result ; return result ;
} }
case UFRIGHT: case UFRIGHT: {
return (strcpy(result, int sz ;
&arg1[(strlen(arg1) - atoi(arg2))]));
sz = atoi( arg2) ;
if( sz >= ressize) {
free( result) ;
result = malloc( sz + 1) ;
ressize = sz + 1 ;
}
return strcpy( result, &arg1[ strlen( arg1) - sz]) ;
}
case UFMID: { case UFMID: {
int sz ; int sz ;
sz = atoi( arg3) ; sz = atoi( arg3) ;
if( sz >= ressize) if( sz >= ressize) {
sz = ressize - 1 ; free( result) ;
result = malloc( sz + 1) ;
ressize = sz + 1 ;
}
strncpy( result, &arg1[ atoi( arg2) - 1], sz) ; strncpy( result, &arg1[ atoi( arg2) - 1], sz) ;
result[ sz] = 0 ; result[ sz] = 0 ;
return result ; return result ;