aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2018-12-10 20:26:04 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2018-12-10 20:26:04 +0100
commit88cfea6a818b83a4681b04ad812d3cc047af15b9 (patch)
treedd8027b38b1d1de9e36e6210ae455483a66e2cf3
parentfa35e598ab3d98037d0db05b257f787ecb4b7a74 (diff)
downloadbusybox-w32-88cfea6a818b83a4681b04ad812d3cc047af15b9.tar.gz
busybox-w32-88cfea6a818b83a4681b04ad812d3cc047af15b9.tar.bz2
busybox-w32-88cfea6a818b83a4681b04ad812d3cc047af15b9.zip
bc: stop checking for name length in bc_lex_name()
Gigabyte-long names are not a practical concern. function old new delta bc_lex_name 73 69 -4 bc_lex_token 1266 1259 -7 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-11) Total: -11 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--miscutils/bc.c30
1 files changed, 21 insertions, 9 deletions
diff --git a/miscutils/bc.c b/miscutils/bc.c
index 3b9b4d54e..aa0a2c636 100644
--- a/miscutils/bc.c
+++ b/miscutils/bc.c
@@ -3020,27 +3020,34 @@ static BcStatus bc_lex_number(BcLex *l, char start)
3020# define bc_lex_number(...) (bc_lex_number(__VA_ARGS__), BC_STATUS_SUCCESS) 3020# define bc_lex_number(...) (bc_lex_number(__VA_ARGS__), BC_STATUS_SUCCESS)
3021#endif 3021#endif
3022 3022
3023static BcStatus bc_lex_name(BcLex *l) 3023static void bc_lex_name(BcLex *l)
3024{ 3024{
3025 size_t i = 0; 3025 size_t i;
3026 const char *buf = l->buf + l->i - 1; 3026 const char *buf;
3027 char c = buf[i];
3028 3027
3029 l->t.t = BC_LEX_NAME; 3028 l->t.t = BC_LEX_NAME;
3030 3029
3031 while ((c >= 'a' && c <= 'z') || isdigit(c) || c == '_') c = buf[++i]; 3030 i = 0;
3031 buf = l->buf + l->i - 1;
3032 for (;;) {
3033 char c = buf[i];
3034 if ((c < 'a' || c > 'z') && !isdigit(c) && c != '_') break;
3035 i++;
3036 }
3032 3037
3038#if 0 // We do not protect against people with gigabyte-long names
3033 // This check makes sense only if size_t is (much) larger than BC_MAX_STRING. 3039 // This check makes sense only if size_t is (much) larger than BC_MAX_STRING.
3034 if (SIZE_MAX > (BC_MAX_STRING | 0xff)) { 3040 if (SIZE_MAX > (BC_MAX_STRING | 0xff)) {
3035 if (i > BC_MAX_STRING) 3041 if (i > BC_MAX_STRING)
3036 return bc_error("name too long: must be [1,"BC_MAX_STRING_STR"]"); 3042 return bc_error("name too long: must be [1,"BC_MAX_STRING_STR"]");
3037 } 3043 }
3044#endif
3038 bc_vec_string(&l->t.v, i, buf); 3045 bc_vec_string(&l->t.v, i, buf);
3039 3046
3040 // Increment the index. We minus 1 because it has already been incremented. 3047 // Increment the index. We minus 1 because it has already been incremented.
3041 l->i += i - 1; 3048 l->i += i - 1;
3042 3049
3043 return BC_STATUS_SUCCESS; 3050 //return BC_STATUS_SUCCESS;
3044} 3051}
3045 3052
3046static void bc_lex_init(BcLex *l, BcLexNext next) 3053static void bc_lex_init(BcLex *l, BcLexNext next)
@@ -3121,8 +3128,7 @@ static BcStatus bc_lex_identifier(BcLex *l)
3121 return BC_STATUS_SUCCESS; 3128 return BC_STATUS_SUCCESS;
3122 } 3129 }
3123 3130
3124 s = bc_lex_name(l); 3131 bc_lex_name(l);
3125 if (s) return s;
3126 3132
3127 if (l->t.v.len > 2) { 3133 if (l->t.v.len > 2) {
3128 // Prevent this: 3134 // Prevent this:
@@ -3498,7 +3504,7 @@ static BcStatus dc_lex_register(BcLex *l)
3498 if (!G_exreg) 3504 if (!G_exreg)
3499 s = bc_error("extended register"); 3505 s = bc_error("extended register");
3500 else 3506 else
3501 s = bc_lex_name(l); 3507 bc_lex_name(l);
3502 } 3508 }
3503 else { 3509 else {
3504 bc_vec_pop_all(&l->t.v); 3510 bc_vec_pop_all(&l->t.v);
@@ -3509,6 +3515,9 @@ static BcStatus dc_lex_register(BcLex *l)
3509 3515
3510 return s; 3516 return s;
3511} 3517}
3518#if ERRORS_ARE_FATAL
3519# define dc_lex_register(...) (dc_lex_register(__VA_ARGS__), BC_STATUS_SUCCESS)
3520#endif
3512 3521
3513static BcStatus dc_lex_string(BcLex *l) 3522static BcStatus dc_lex_string(BcLex *l)
3514{ 3523{
@@ -3545,6 +3554,9 @@ static BcStatus dc_lex_string(BcLex *l)
3545 3554
3546 return BC_STATUS_SUCCESS; 3555 return BC_STATUS_SUCCESS;
3547} 3556}
3557#if ERRORS_ARE_FATAL
3558# define dc_lex_string(...) (dc_lex_string(__VA_ARGS__), BC_STATUS_SUCCESS)
3559#endif
3548 3560
3549static FAST_FUNC BcStatus dc_lex_token(BcLex *l) 3561static FAST_FUNC BcStatus dc_lex_token(BcLex *l)
3550{ 3562{