summaryrefslogtreecommitdiffhomepage
path: root/mrbgems/mruby-bin-debugger/tools/mrdb/apibreak.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/apibreak.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/apibreak.c')
-rw-r--r--mrbgems/mruby-bin-debugger/tools/mrdb/apibreak.c18
1 files changed, 7 insertions, 11 deletions
diff --git a/mrbgems/mruby-bin-debugger/tools/mrdb/apibreak.c b/mrbgems/mruby-bin-debugger/tools/mrdb/apibreak.c
index 4d139aa76..137f52431 100644
--- a/mrbgems/mruby-bin-debugger/tools/mrdb/apibreak.c
+++ b/mrbgems/mruby-bin-debugger/tools/mrdb/apibreak.c
@@ -14,6 +14,7 @@
#include <mruby/variable.h>
#include "mrdberror.h"
#include "apibreak.h"
+#include "apistring.h"
#define MAX_BREAKPOINTNO (MAX_BREAKPOINT * 1024)
#define MRB_DEBUG_BP_FILE_OK (0x0001)
@@ -197,7 +198,7 @@ mrb_debug_set_break_line(mrb_state *mrb, mrb_debug_context *dbg, const char *fil
}
len = strlen(file) + 1;
- set_file = (char*)mrb_malloc(mrb, len);
+ set_file = mrb_debug_strdup(mrb, file);
index = dbg->bpnum;
dbg->bp[index].bpno = dbg->next_bpno;
@@ -207,8 +208,6 @@ mrb_debug_set_break_line(mrb_state *mrb, mrb_debug_context *dbg, const char *fil
dbg->bp[index].point.linepoint.lineno = lineno;
dbg->bpnum++;
- strncpy(set_file, file, len);
-
dbg->bp[index].point.linepoint.file = set_file;
return dbg->bp[index].bpno;
@@ -220,7 +219,6 @@ mrb_debug_set_break_method(mrb_state *mrb, mrb_debug_context *dbg, const char *c
int32_t index;
char* set_class;
char* set_method;
- size_t len;
if ((mrb == NULL) || (dbg == NULL) || (method_name == NULL)) {
return MRB_DEBUG_INVALID_ARGUMENT;
@@ -235,18 +233,16 @@ mrb_debug_set_break_method(mrb_state *mrb, mrb_debug_context *dbg, const char *c
}
if (class_name != NULL) {
- len = strlen(class_name) + 1;
- set_class = (char*)mrb_malloc(mrb, len);
- strncpy(set_class, class_name, len);
+ set_class = mrb_debug_strdup(mrb, class_name);
}
else {
set_class = NULL;
}
- len = strlen(method_name) + 1;
- set_method = (char*)mrb_malloc(mrb, len);
-
- strncpy(set_method, method_name, len);
+ set_method = mrb_debug_strdup(mrb, method_name);
+ if (set_method == NULL) {
+ mrb_free(mrb, set_class);
+ }
index = dbg->bpnum;
dbg->bp[index].bpno = dbg->next_bpno;