modules/mruby/mrbgems/mruby-bin-mruby/tools/mruby/mruby.c in webruby-0.1.1 vs modules/mruby/mrbgems/mruby-bin-mruby/tools/mruby/mruby.c in webruby-0.1.2
- old
+ new
@@ -89,19 +89,27 @@
else if (argc > 1) {
argc--; argv++;
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 {
printf("%s: No code specified for -e\n", *origargv);
return EXIT_SUCCESS;