Merge pull request #1445 from cremno/no_strcpy_and_strcat

don't use str{cpy,cat} in mruby and mrbc
This commit is contained in:
Yukihiro "Matz" Matsumoto
2013-08-07 16:23:31 -07:00
3 changed files with 34 additions and 14 deletions
+13 -5
View File
@@ -3701,7 +3701,9 @@ parse_string(parser_state *p)
int f = 0;
int c;
char *s = strndup(tok(p), toklen(p));
char flag[4] = { '\0' };
char flags[3];
char *flag = flags;
char *dup;
newtok(p);
while (c = nextc(p), c != -1 && ISALPHA(c)) {
@@ -3720,10 +3722,16 @@ parse_string(parser_state *p)
toklen(p) > 1 ? "s" : "", tok(p));
yyerror(p, msg);
}
if (f & 1) strcat(flag, "i");
if (f & 2) strcat(flag, "x");
if (f & 4) strcat(flag, "m");
yylval.nd = new_regx(p, s, strdup(flag));
if (f != 0) {
if (f & 1) *flag++ = 'i';
if (f & 2) *flag++ = 'x';
if (f & 4) *flag++ = 'm';
dup = strndup(flags, (size_t)(flag - flags));
}
else {
dup = NULL;
}
yylval.nd = new_regx(p, s, dup);
return tREGEXP;
}