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) ...@@ -91,16 +91,24 @@ parse_args(mrb_state *mrb, int argc, char **argv, struct _args *args)
item = argv[0]; item = argv[0];
append_cmdline: append_cmdline:
if (!args->cmdline) { if (!args->cmdline) {
size_t buflen;
char *buf; char *buf;
buf = (char *)mrb_malloc(mrb, strlen(item)+1); buflen = strlen(item) + 1;
strcpy(buf, item); buf = (char *)mrb_malloc(mrb, buflen);
memcpy(buf, item, buflen);
args->cmdline = buf; args->cmdline = buf;
} }
else { else {
args->cmdline = (char *)mrb_realloc(mrb, args->cmdline, strlen(args->cmdline)+strlen(item)+2); size_t cmdlinelen;
strcat(args->cmdline, "\n"); size_t itemlen;
strcat(args->cmdline, item);
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 { else {
......
...@@ -3701,7 +3701,9 @@ parse_string(parser_state *p) ...@@ -3701,7 +3701,9 @@ parse_string(parser_state *p)
int f = 0; int f = 0;
int c; int c;
char *s = strndup(tok(p), toklen(p)); char *s = strndup(tok(p), toklen(p));
char flag[4] = { '\0' }; char flags[3];
char *flag = flags;
char *dup;
newtok(p); newtok(p);
while (c = nextc(p), c != -1 && ISALPHA(c)) { while (c = nextc(p), c != -1 && ISALPHA(c)) {
...@@ -3720,10 +3722,16 @@ parse_string(parser_state *p) ...@@ -3720,10 +3722,16 @@ parse_string(parser_state *p)
toklen(p) > 1 ? "s" : "", tok(p)); toklen(p) > 1 ? "s" : "", tok(p));
yyerror(p, msg); yyerror(p, msg);
} }
if (f & 1) strcat(flag, "i"); if (f != 0) {
if (f & 2) strcat(flag, "x"); if (f & 1) *flag++ = 'i';
if (f & 4) strcat(flag, "m"); if (f & 2) *flag++ = 'x';
yylval.nd = new_regx(p, s, strdup(flag)); if (f & 4) *flag++ = 'm';
dup = strndup(flags, (size_t)(flag - flags));
}
else {
dup = NULL;
}
yylval.nd = new_regx(p, s, dup);
return tREGEXP; return tREGEXP;
} }
......
...@@ -51,15 +51,19 @@ usage(const char *name) ...@@ -51,15 +51,19 @@ usage(const char *name)
static char * static char *
get_outfilename(mrb_state *mrb, char *infile, char *ext) get_outfilename(mrb_state *mrb, char *infile, char *ext)
{ {
size_t infilelen;
size_t extlen;
char *outfile; char *outfile;
char *p; char *p;
outfile = (char*)mrb_malloc(mrb, strlen(infile) + strlen(ext) + 1); infilelen = strlen(infile);
strcpy(outfile, infile); extlen = strlen(ext);
outfile = (char*)mrb_malloc(mrb, infilelen + extlen + 1);
memcpy(outfile, infile, infilelen + 1);
if (*ext) { if (*ext) {
if ((p = strrchr(outfile, '.')) == NULL) if ((p = strrchr(outfile, '.')) == NULL)
p = &outfile[strlen(outfile)]; p = outfile + infilelen;
strcpy(p, ext); memcpy(p, ext, extlen + 1);
} }
return outfile; 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