From: Denys Vlasenko Date: Mon, 10 Dec 2018 19:26:04 +0000 (+0100) Subject: bc: stop checking for name length in bc_lex_name() X-Git-Tag: 1_30_0~224 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=88cfea6a818b83a4681b04ad812d3cc047af15b9;p=oweals%2Fbusybox.git 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 --- 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) # define bc_lex_number(...) (bc_lex_number(__VA_ARGS__), BC_STATUS_SUCCESS) #endif -static BcStatus bc_lex_name(BcLex *l) +static void bc_lex_name(BcLex *l) { - size_t i = 0; - const char *buf = l->buf + l->i - 1; - char c = buf[i]; + size_t i; + const char *buf; l->t.t = BC_LEX_NAME; - while ((c >= 'a' && c <= 'z') || isdigit(c) || c == '_') c = buf[++i]; + i = 0; + buf = l->buf + l->i - 1; + for (;;) { + char c = buf[i]; + if ((c < 'a' || c > 'z') && !isdigit(c) && c != '_') break; + i++; + } +#if 0 // We do not protect against people with gigabyte-long names // This check makes sense only if size_t is (much) larger than BC_MAX_STRING. if (SIZE_MAX > (BC_MAX_STRING | 0xff)) { if (i > BC_MAX_STRING) return bc_error("name too long: must be [1,"BC_MAX_STRING_STR"]"); } +#endif bc_vec_string(&l->t.v, i, buf); // Increment the index. We minus 1 because it has already been incremented. l->i += i - 1; - return BC_STATUS_SUCCESS; + //return BC_STATUS_SUCCESS; } static void bc_lex_init(BcLex *l, BcLexNext next) @@ -3121,8 +3128,7 @@ static BcStatus bc_lex_identifier(BcLex *l) return BC_STATUS_SUCCESS; } - s = bc_lex_name(l); - if (s) return s; + bc_lex_name(l); if (l->t.v.len > 2) { // Prevent this: @@ -3498,7 +3504,7 @@ static BcStatus dc_lex_register(BcLex *l) if (!G_exreg) s = bc_error("extended register"); else - s = bc_lex_name(l); + bc_lex_name(l); } else { bc_vec_pop_all(&l->t.v); @@ -3509,6 +3515,9 @@ static BcStatus dc_lex_register(BcLex *l) return s; } +#if ERRORS_ARE_FATAL +# define dc_lex_register(...) (dc_lex_register(__VA_ARGS__), BC_STATUS_SUCCESS) +#endif static BcStatus dc_lex_string(BcLex *l) { @@ -3545,6 +3554,9 @@ static BcStatus dc_lex_string(BcLex *l) return BC_STATUS_SUCCESS; } +#if ERRORS_ARE_FATAL +# define dc_lex_string(...) (dc_lex_string(__VA_ARGS__), BC_STATUS_SUCCESS) +#endif static FAST_FUNC BcStatus dc_lex_token(BcLex *l) {