diff options
Diffstat (limited to 'mrbgems/mruby-bin-debugger/tools/mrdb/apilist.c')
| -rw-r--r-- | mrbgems/mruby-bin-debugger/tools/mrdb/apilist.c | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/mrbgems/mruby-bin-debugger/tools/mrdb/apilist.c b/mrbgems/mruby-bin-debugger/tools/mrdb/apilist.c index 21fe64127..368ececcf 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> @@ -65,7 +66,6 @@ dirname(mrb_state *mrb, const char *path) { size_t len; const char *p; - char *dir; if (path == NULL) { return NULL; @@ -74,11 +74,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 mrdb_strndup(mrb, path, len); } static source_file* @@ -97,8 +93,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 = mrdb_strdup(mrb, filename); + if (file->path == NULL) { + source_file_free(mrb, file); + return NULL; + } return file; } @@ -181,7 +180,7 @@ mrb_debug_get_source(mrb_state *mrb, mrdb_state *mrdb, const char *srcpath, cons else srcname = filename; search_path[0] = srcpath; - search_path[1] = dirname(mrb, mrb_debug_get_filename(mrdb->dbg->irep, 0)); + search_path[1] = dirname(mrb, mrb_debug_get_filename(mrb, mrdb->dbg->irep, 0)); search_path[2] = "."; for (i = 0; i < 3; i++) { |
