From: Michael Stapelberg Date: Fri, 21 Oct 2011 22:09:57 +0000 (+0100) Subject: cfgparse: Don’t use asprintf when parsing hex colors X-Git-Tag: 4.1~92^2~8 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=77961ad9c84ade490da8d79578be764a4e77053c;p=i3%2Fi3 cfgparse: Don’t use asprintf when parsing hex colors --- diff --git a/src/cfgparse.l b/src/cfgparse.l index 50fbc6ca..39e1d398 100644 --- a/src/cfgparse.l +++ b/src/cfgparse.l @@ -138,7 +138,7 @@ EOL (\r?\n) [^\n]+ { yy_pop_state(); yylval.string = sstrdup(yytext); return STR; } [a-zA-Z0-9_-]+ { yy_pop_state(); yylval.string = sstrdup(yytext); return OUTPUT; } ^[ \t]*#[^\n]* { return TOKCOMMENT; } -[0-9a-fA-F]+ { yy_pop_state(); yylval.string = sstrdup(yytext); return HEX; } +#[0-9a-fA-F]+ { yy_pop_state(); yylval.string = sstrdup(yytext+1); return HEXCOLOR; } [ \t]*→[ \t]* { BEGIN(WANT_STRING); } [ \t]+ { BEGIN(WANT_STRING); } [0-9]+ { yylval.number = atoi(yytext); return NUMBER; } diff --git a/src/cfgparse.y b/src/cfgparse.y index c9e1eb98..bc4928f6 100644 --- a/src/cfgparse.y +++ b/src/cfgparse.y @@ -590,7 +590,6 @@ void parse_file(const char *f) { %token WORD "" %token STR "" %token STR_NG "" -%token HEX "" %token HEXCOLOR "#" %token OUTPUT "" %token TOKBINDCODE @@ -1506,14 +1505,10 @@ color: ; colorpixel: - '#' HEX + HEXCOLOR { - char *hex; - if (asprintf(&hex, "#%s", $2) == -1) - die("asprintf()"); - free($2); - $$ = get_colorpixel(hex); - free(hex); + $$ = get_colorpixel($1); + free($1); } ;