Use `snprintf` instead of `memcpy` in `mrbc.c`.

parent c07f24cd
...@@ -53,19 +53,13 @@ static char * ...@@ -53,19 +53,13 @@ static char *
get_outfilename(mrb_state *mrb, char *infile, const char *ext) get_outfilename(mrb_state *mrb, char *infile, const char *ext)
{ {
size_t infilelen; size_t infilelen;
size_t extlen; size_t flen;
char *outfile; char *outfile;
char *p;
infilelen = strlen(infile); infilelen = strlen(infile);
extlen = strlen(ext); flen = infilelen + strlen(ext) + 1;
outfile = (char*)mrb_malloc(mrb, infilelen + extlen + 1); outfile = (char*)mrb_malloc(mrb, flen);
memcpy(outfile, infile, infilelen + 1); snprintf(outfile, flen, "%s%s", infile, ext);
if (*ext) {
if ((p = strrchr(outfile, '.')) == NULL)
p = outfile + infilelen;
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