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>
# define bc_lex_number(...) (bc_lex_number(__VA_ARGS__), BC_STATUS_SUCCESS)
#endif
# 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;
- 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"]");
}
// 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"]");
}
bc_vec_string(&l->t.v, i, buf);
// Increment the index. We minus 1 because it has already been incremented.
l->i += i - 1;
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)
}
static void bc_lex_init(BcLex *l, BcLexNext next)
return BC_STATUS_SUCCESS;
}
return BC_STATUS_SUCCESS;
}
- s = bc_lex_name(l);
- if (s) return s;
if (l->t.v.len > 2) {
// Prevent this:
if (l->t.v.len > 2) {
// Prevent this:
if (!G_exreg)
s = bc_error("extended register");
else
if (!G_exreg)
s = bc_error("extended register");
else
}
else {
bc_vec_pop_all(&l->t.v);
}
else {
bc_vec_pop_all(&l->t.v);
+#if ERRORS_ARE_FATAL
+# define dc_lex_register(...) (dc_lex_register(__VA_ARGS__), BC_STATUS_SUCCESS)
+#endif
static BcStatus dc_lex_string(BcLex *l)
{
static BcStatus dc_lex_string(BcLex *l)
{
return BC_STATUS_SUCCESS;
}
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)
{
static FAST_FUNC BcStatus dc_lex_token(BcLex *l)
{