Merge branch 'mrb_debug_strdup-and-strndup' of https://github.com/cremno/mruby into...
authorYukihiro "Matz" Matsumoto <[email protected]>
Tue, 6 Jul 2021 08:01:37 +0000 (6 17:01 +0900)
committerYukihiro "Matz" Matsumoto <[email protected]>
Tue, 6 Jul 2021 08:01:37 +0000 (6 17:01 +0900)
1  2 
mrbgems/mruby-bin-debugger/tools/mrdb/apibreak.c
mrbgems/mruby-bin-debugger/tools/mrdb/apilist.c
mrbgems/mruby-bin-debugger/tools/mrdb/cmdmisc.c

index 4d139aa,9515e8b..137f524
mode 100644,100755..100644
@@@ -4,16 -4,17 +4,17 @@@
  */
  
  #include <string.h>
 -#include "mruby.h"
 -#include "mruby/irep.h"
 +#include <mruby.h>
 +#include <mruby/irep.h>
  #include "mrdb.h"
 -#include "mruby/debug.h"
 -#include "mruby/opcode.h"
 -#include "mruby/class.h"
 -#include "mruby/proc.h"
 -#include "mruby/variable.h"
 +#include <mruby/debug.h>
 +#include <mruby/opcode.h>
 +#include <mruby/class.h>
 +#include <mruby/proc.h>
 +#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)
@@@ -188,16 -196,17 +189,16 @@@ mrb_debug_set_break_line(mrb_state *mrb
    }
  
    /* file and lineno check (line type mrb_debug_line_ary only.) */
 -  result = check_file_lineno( dbg->root_irep, file, lineno );
 -  if(result == 0) {
 +  result = check_file_lineno(mrb, dbg->root_irep, file, lineno);
 +  if (result == 0) {
      return MRB_DEBUG_BREAK_INVALID_FILE;
 -  }else if(result == MRB_DEBUG_BP_FILE_OK) {
 +  }
 +  else if (result == MRB_DEBUG_BP_FILE_OK) {
      return MRB_DEBUG_BREAK_INVALID_LINENO;
 -  } 
 +  }
  
-   set_file = (char*)mrb_malloc(mrb, len);
 +  len = strlen(file) + 1;
 -  if(set_file == NULL) {
 -    return MRB_DEBUG_NOBUF;
 -  }
+   set_file = mrb_debug_strdup(mrb, file);
  
    index = dbg->bpnum;
    dbg->bp[index].bpno = dbg->next_bpno;
@@@ -220,9 -227,8 +219,8 @@@ mrb_debug_set_break_method(mrb_state *m
    int32_t index;
    char* set_class;
    char* set_method;
-   size_t len;
  
 -  if((mrb == NULL) || (dbg == NULL) || (method_name == NULL)) {
 +  if ((mrb == NULL) || (dbg == NULL) || (method_name == NULL)) {
      return MRB_DEBUG_INVALID_ARGUMENT;
    }
  
      return MRB_DEBUG_BREAK_NO_OVER;
    }
  
 -  if(class_name != NULL) {
 +  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);
 -    if(set_class == NULL) {
 -      return MRB_DEBUG_NOBUF;
 -    }
    }
    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) {
 -    if(set_class != NULL) {
 -      mrb_free(mrb, (void*)set_class);
 -    }
 -    return MRB_DEBUG_NOBUF;
++  if (set_method == NULL) {
++    mrb_free(mrb, set_class);
+   }
  
    index = dbg->bpnum;
    dbg->bp[index].bpno = dbg->next_bpno;
index 66ddfa7,8eddc7b..ef80872
mode 100644,100755..100644
@@@ -9,9 -9,10 +9,10 @@@
  #include "mrdb.h"
  #include "mrdberror.h"
  #include "apilist.h"
 -#include "mruby/compile.h"
 -#include "mruby/irep.h"
 -#include "mruby/debug.h"
+ #include "apistring.h"
 +#include <mruby/compile.h>
 +#include <mruby/irep.h>
 +#include <mruby/debug.h>
  
  #define LINE_BUF_SIZE MAX_COMMAND_LINE
  
@@@ -72,13 -72,9 +73,9 @@@ dirname(mrb_state *mrb, const char *pat
    }
  
    p = strrchr(path, '/');
 -  len = p != NULL ? p - path : strlen(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 -95,10 +94,11 @@@ source_file_new(mrb_state *mrb, mrb_deb
    }
  
    file->lineno = 1;
-   file->path = (char*)mrb_malloc(mrb, strlen(filename) + 1);
-   strcpy(file->path, filename);
 -  if ((file->path = mrb_debug_strdup(mrb, filename)) == NULL) {
++  file->path = mrb_debug_strdup(mrb, filename);
++  if (file->path == NULL) {
+     source_file_free(mrb, file);
+     return NULL;
+   }
    return file;
  }
  
index a05ff94,7b0806e..fde65fb
mode 100644,100755..100644
@@@ -8,7 -8,8 +8,8 @@@
  #include <string.h>
  
  #include "apilist.h"
 -#include "mruby/compile.h"
+ #include "apistring.h"
 +#include <mruby/compile.h>
  
  typedef struct help_msg {
    const char *cmd1;