Commit 3b2b760e authored by Yukihiro "Matz" Matsumoto's avatar Yukihiro "Matz" Matsumoto

Merge pull request #1445 from cremno/no_strcpy_and_strcat

don't use str{cpy,cat} in mruby and mrbc
parents d2be1542 29381bc8
......@@ -91,16 +91,24 @@ parse_args(mrb_state *mrb, int argc, char **argv, struct _args *args)
item = argv[0];
append_cmdline:
if (!args->cmdline) {
size_t buflen;
char *buf;
buf = (char *)mrb_malloc(mrb, strlen(item)+1);
strcpy(buf, item);
buflen = strlen(item) + 1;
buf = (char *)mrb_malloc(mrb, buflen);
memcpy(buf, item, buflen);
args->cmdline = buf;
}
else {
args->cmdline = (char *)mrb_realloc(mrb, args->cmdline, strlen(args->cmdline)+strlen(item)+2);
strcat(args->cmdline, "\n");
strcat(args->cmdline, item);
size_t cmdlinelen;
size_t itemlen;
cmdlinelen = strlen(args->cmdline);
itemlen = strlen(item);
args->cmdline =
(char *)mrb_realloc(mrb, args->cmdline, cmdlinelen + itemlen + 2);
args->cmdline[cmdlinelen] = '\n';
memcpy(args->cmdline + cmdlinelen + 1, item, itemlen + 1);
}
}
else {
......
......@@ -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;
}
......
......@@ -51,15 +51,19 @@ usage(const char *name)
static char *
get_outfilename(mrb_state *mrb, char *infile, char *ext)
{
size_t infilelen;
size_t extlen;
char *outfile;
char *p;
outfile = (char*)mrb_malloc(mrb, strlen(infile) + strlen(ext) + 1);
strcpy(outfile, infile);
infilelen = strlen(infile);
extlen = strlen(ext);
outfile = (char*)mrb_malloc(mrb, infilelen + extlen + 1);
memcpy(outfile, infile, infilelen + 1);
if (*ext) {
if ((p = strrchr(outfile, '.')) == NULL)
p = &outfile[strlen(outfile)];
strcpy(p, ext);
p = outfile + infilelen;
memcpy(p, ext, extlen + 1);
}
return outfile;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment