diff options
| author | Denys Vlasenko <vda.linux@googlemail.com> | 2017-07-26 14:38:19 +0200 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2017-07-26 14:38:19 +0200 |
| commit | cf3a796dd1dfe53f7d67507f7f4d5c05cc7ebc8d (patch) | |
| tree | efdfacffd404ba36ebd19ecff069768896235570 /shell | |
| parent | b31b61bb9bff8a920b7e25b83e3aa08f7c907331 (diff) | |
| download | busybox-w32-cf3a796dd1dfe53f7d67507f7f4d5c05cc7ebc8d.tar.gz busybox-w32-cf3a796dd1dfe53f7d67507f7f4d5c05cc7ebc8d.tar.bz2 busybox-w32-cf3a796dd1dfe53f7d67507f7f4d5c05cc7ebc8d.zip | |
ash: alloc slightly smaller buffer in cvtnum(); faster unsetvar()
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'shell')
| -rw-r--r-- | shell/ash.c | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/shell/ash.c b/shell/ash.c index 524580e8a..915e86167 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
| @@ -214,6 +214,9 @@ | |||
| 214 | #include "shell_common.h" | 214 | #include "shell_common.h" |
| 215 | #if ENABLE_FEATURE_SH_MATH | 215 | #if ENABLE_FEATURE_SH_MATH |
| 216 | # include "math.h" | 216 | # include "math.h" |
| 217 | #else | ||
| 218 | typedef long arith_t; | ||
| 219 | # define ARITH_FMT "%ld" | ||
| 217 | #endif | 220 | #endif |
| 218 | #if ENABLE_ASH_RANDOM_SUPPORT | 221 | #if ENABLE_ASH_RANDOM_SUPPORT |
| 219 | # include "random.h" | 222 | # include "random.h" |
| @@ -621,8 +624,8 @@ fmtstr(char *outbuf, size_t length, const char *fmt, ...) | |||
| 621 | va_list ap; | 624 | va_list ap; |
| 622 | int ret; | 625 | int ret; |
| 623 | 626 | ||
| 624 | va_start(ap, fmt); | ||
| 625 | INT_OFF; | 627 | INT_OFF; |
| 628 | va_start(ap, fmt); | ||
| 626 | ret = vsnprintf(outbuf, length, fmt, ap); | 629 | ret = vsnprintf(outbuf, length, fmt, ap); |
| 627 | va_end(ap); | 630 | va_end(ap); |
| 628 | INT_ON; | 631 | INT_ON; |
| @@ -2345,7 +2348,7 @@ setvar0(const char *name, const char *val) | |||
| 2345 | static void | 2348 | static void |
| 2346 | unsetvar(const char *s) | 2349 | unsetvar(const char *s) |
| 2347 | { | 2350 | { |
| 2348 | setvar0(s, NULL); | 2351 | setvar(s, NULL, 0); |
| 2349 | } | 2352 | } |
| 2350 | 2353 | ||
| 2351 | /* | 2354 | /* |
| @@ -5697,19 +5700,20 @@ static struct arglist exparg; | |||
| 5697 | 5700 | ||
| 5698 | /* | 5701 | /* |
| 5699 | * Our own itoa(). | 5702 | * Our own itoa(). |
| 5703 | * cvtnum() is used even if math support is off (to prepare $? values and such). | ||
| 5700 | */ | 5704 | */ |
| 5701 | #if !ENABLE_FEATURE_SH_MATH | ||
| 5702 | /* cvtnum() is used even if math support is off (to prepare $? values and such) */ | ||
| 5703 | typedef long arith_t; | ||
| 5704 | # define ARITH_FMT "%ld" | ||
| 5705 | #endif | ||
| 5706 | static int | 5705 | static int |
| 5707 | cvtnum(arith_t num) | 5706 | cvtnum(arith_t num) |
| 5708 | { | 5707 | { |
| 5709 | int len; | 5708 | int len; |
| 5710 | 5709 | ||
| 5711 | expdest = makestrspace(sizeof(arith_t)*3 + 2, expdest); | 5710 | /* 32-bit and wider ints require buffer size of bytes*3 (or less) */ |
| 5712 | len = fmtstr(expdest, sizeof(arith_t)*3 + 2, ARITH_FMT, num); | 5711 | len = sizeof(arith_t) * 3; |
| 5712 | /* If narrower: worst case, 1-byte ints: need 5 bytes: "-127<NUL>" */ | ||
| 5713 | if (sizeof(arith_t) < 4) len += 2; | ||
| 5714 | |||
| 5715 | expdest = makestrspace(len, expdest); | ||
| 5716 | len = fmtstr(expdest, len, ARITH_FMT, num); | ||
| 5713 | STADJUST(len, expdest); | 5717 | STADJUST(len, expdest); |
| 5714 | return len; | 5718 | return len; |
| 5715 | } | 5719 | } |
