summaryrefslogtreecommitdiff
path: root/miscutils/bc.c
diff options
context:
space:
mode:
authorDenys Vlasenko2018-12-10 20:26:04 +0100
committerDenys Vlasenko2018-12-10 20:26:04 +0100
commit88cfea6a818b83a4681b04ad812d3cc047af15b9 (patch)
treedd8027b38b1d1de9e36e6210ae455483a66e2cf3 /miscutils/bc.c
parentfa35e598ab3d98037d0db05b257f787ecb4b7a74 (diff)
downloadbusybox-88cfea6a818b83a4681b04ad812d3cc047af15b9.zip
busybox-88cfea6a818b83a4681b04ad812d3cc047af15b9.tar.gz
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>
Diffstat (limited to 'miscutils/bc.c')
-rw-r--r--miscutils/bc.c30
1 files changed, 21 insertions, 9 deletions
diff --git a/miscutils/bc.c b/miscutils/bc.c
index 3b9b4d5..aa0a2c6 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)
{