From ba027d7806e00be6b34b2539f42b9f31e218ab91 Mon Sep 17 00:00:00 2001 From: Cremno Date: Wed, 7 Aug 2013 19:58:06 +0200 Subject: don't use str{cpy,cat} in mruby and mrbc The length of each string is known. It should be used. --- tools/mrbc/mrbc.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'tools/mrbc/mrbc.c') diff --git a/tools/mrbc/mrbc.c b/tools/mrbc/mrbc.c index 79fcd2bdf..735b22b1d 100644 --- a/tools/mrbc/mrbc.c +++ b/tools/mrbc/mrbc.c @@ -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; -- cgit v1.2.3