summaryrefslogtreecommitdiffhomepage
path: root/mrbgems/mruby-bin-debugger/tools/mrdb/apilist.c
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2021-07-06 17:01:37 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2021-07-06 17:01:37 +0900
commit7c362ee7237ec31e4e4b1bf3cc81f59e86c83573 (patch)
tree5b1f2323812995d217e5c85e5f37fb88a50bd368 /mrbgems/mruby-bin-debugger/tools/mrdb/apilist.c
parent7fa0a704e010b4a9d1ac96da9f8a0ffc4cb13c2e (diff)
parentf31733045feee3c381ee350be64e1a83682d5543 (diff)
downloadmruby-7c362ee7237ec31e4e4b1bf3cc81f59e86c83573.tar.gz
mruby-7c362ee7237ec31e4e4b1bf3cc81f59e86c83573.zip
Merge branch 'mrb_debug_strdup-and-strndup' of https://github.com/cremno/mruby into cremno-mrb_debug_strdup-and-strndup
Diffstat (limited to 'mrbgems/mruby-bin-debugger/tools/mrdb/apilist.c')
-rw-r--r--mrbgems/mruby-bin-debugger/tools/mrdb/apilist.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/mrbgems/mruby-bin-debugger/tools/mrdb/apilist.c b/mrbgems/mruby-bin-debugger/tools/mrdb/apilist.c
index 66ddfa783..ef80872e5 100644
--- a/mrbgems/mruby-bin-debugger/tools/mrdb/apilist.c
+++ b/mrbgems/mruby-bin-debugger/tools/mrdb/apilist.c
@@ -9,6 +9,7 @@
#include "mrdb.h"
#include "mrdberror.h"
#include "apilist.h"
+#include "apistring.h"
#include <mruby/compile.h>
#include <mruby/irep.h>
#include <mruby/debug.h>
@@ -74,11 +75,7 @@ dirname(mrb_state *mrb, const char *path)
p = strrchr(path, '/');
len = p != NULL ? (size_t)(p - path) : strlen(path);
- dir = (char*)mrb_malloc(mrb, len + 1);
- strncpy(dir, path, len);
- dir[len] = '\0';
-
- return dir;
+ return mrb_debug_strndup(mrb, path, len);
}
static source_file*
@@ -97,8 +94,11 @@ source_file_new(mrb_state *mrb, mrb_debug_context *dbg, char *filename)
}
file->lineno = 1;
- file->path = (char*)mrb_malloc(mrb, strlen(filename) + 1);
- strcpy(file->path, filename);
+ file->path = mrb_debug_strdup(mrb, filename);
+ if (file->path == NULL) {
+ source_file_free(mrb, file);
+ return NULL;
+ }
return file;
}