Commit ba027d78 authored by Cremno's avatar Cremno

don't use str{cpy,cat} in mruby and mrbc

The length of each string is known. It should be used.
parent 1f5c91d6
...@@ -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 {
......
...@@ -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