Skip to content

Commit

Permalink
🎨 hunt strlen in lexer
Browse files Browse the repository at this point in the history
  • Loading branch information
fennecdjay committed Jan 29, 2024
1 parent 6477df1 commit 8fbe63f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
12 changes: 6 additions & 6 deletions src/gwion.l
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ NUM ([0-9]{1,3}+({SPACE}*[0-9]{3})*)
// there was yynoreturn
ANN void lexer_error(yyscan_t yyscanner, const char*, const uint errorcode);
ANN void lex_spread(void *data);
ANN static char* strip_lit(char* str);
ANN static char* strip_lit(char* str, const size_t);
ANN static char* alloc_str(void *, const char* str);
ANN static Symbol alloc_sym(void *, const char* str);
ANN static long long btoll(const char* str);
Expand Down Expand Up @@ -218,7 +218,7 @@ static inline Macro scan_has_macro(Scanner *scan, const m_str id);
while(isspace(*s))++s;
GWYY_LINT(strdup(s), def ? PP_IFNDEF : PP_IFDEF)
while(isspace(*s))++s;
size_t sz = strlen(s);
size_t sz = yyleng;
while(isspace(s[--sz]));
char c[sz + 2];
strncpy(c, s, sz + 1);
Expand Down Expand Up @@ -440,7 +440,7 @@ static inline Macro scan_has_macro(Scanner *scan, const m_str id);
continue;
}

'(\\.|[^\\'])' { adjust(yyscanner); yylval->sval = alloc_str(yyscanner, strip_lit(yytext)); return CHAR_LIT; }
'(\\.|[^\\'])' { adjust(yyscanner); yylval->sval = alloc_str(yyscanner, strip_lit(yytext, yyleng)); return CHAR_LIT; }
. { adjust(yyscanner); lexer_error(yyscanner, _("Stray in program"), 102); return 1;}
%% // LCOV_EXCL_LINE
Expand Down Expand Up @@ -488,9 +488,9 @@ ANN void lexer_error(yyscan_t yyscanner, const char *msg, const uint error_code)
scanner_error(scan, msg, NULL, NULL, *yyget_lloc(yyscanner), error_code);
}

char* strip_lit(char* str){
str[strlen(str)-1] = '\0';
return str+1;
char* strip_lit(char* str, const size_t len){
str[len-1] = '\0';
return str + 1;
}

Symbol alloc_sym(void *data, const char* str) {
Expand Down
12 changes: 6 additions & 6 deletions src/lexer.c
Original file line number Diff line number Diff line change
Expand Up @@ -1433,7 +1433,7 @@ static const flex_int16_t yy_chk[2513] =
// there was yynoreturn
ANN void lexer_error(yyscan_t yyscanner, const char*, const uint errorcode);
ANN void lex_spread(void *data);
ANN static char* strip_lit(char* str);
ANN static char* strip_lit(char* str, const size_t);
ANN static char* alloc_str(void *, const char* str);
ANN static Symbol alloc_sym(void *, const char* str);
ANN static long long btoll(const char* str);
Expand Down Expand Up @@ -2086,7 +2086,7 @@ YY_RULE_SETUP
while(isspace(*s))++s;
GWYY_LINT(strdup(s), def ? PP_IFNDEF : PP_IFDEF)
while(isspace(*s))++s;
size_t sz = strlen(s);
size_t sz = yyleng;
while(isspace(s[--sz]));
char c[sz + 2];
strncpy(c, s, sz + 1);
Expand Down Expand Up @@ -2704,7 +2704,7 @@ case 134:
/* rule 134 can match eol */
YY_RULE_SETUP
#line 443 "src/gwion.l"
{ adjust(yyscanner); yylval->sval = alloc_str(yyscanner, strip_lit(yytext)); return CHAR_LIT; }
{ adjust(yyscanner); yylval->sval = alloc_str(yyscanner, strip_lit(yytext, yyleng)); return CHAR_LIT; }
YY_BREAK
case 135:
YY_RULE_SETUP
Expand Down Expand Up @@ -3856,9 +3856,9 @@ ANN void lexer_error(yyscan_t yyscanner, const char *msg, const uint error_code)
scanner_error(scan, msg, NULL, NULL, *yyget_lloc(yyscanner), error_code);
}

char* strip_lit(char* str){
str[strlen(str)-1] = '\0';
return str+1;
char* strip_lit(char* str, const size_t len){
str[len-1] = '\0';
return str + 1;
}

Symbol alloc_sym(void *data, const char* str) {
Expand Down

0 comments on commit 8fbe63f

Please sign in to comment.