Commit 606095f2 authored by Tatsuhiko Kubo's avatar Tatsuhiko Kubo

Remove redundant NULL checks for mrb_malloc().

parent 4046368e
...@@ -203,9 +203,6 @@ mrb_debug_set_break_line( mrb_state *mrb, mrb_debug_context *dbg, const char *fi ...@@ -203,9 +203,6 @@ mrb_debug_set_break_line( mrb_state *mrb, mrb_debug_context *dbg, const char *fi
} }
set_file = mrb_malloc(mrb, strlen(file) + 1); set_file = mrb_malloc(mrb, strlen(file) + 1);
if(set_file == NULL) {
return MRB_DEBUG_NOBUF;
}
index = dbg->bpnum; index = dbg->bpnum;
dbg->bp[index].bpno = dbg->next_bpno; dbg->bp[index].bpno = dbg->next_bpno;
...@@ -243,10 +240,6 @@ mrb_debug_set_break_method( mrb_state *mrb, mrb_debug_context *dbg, const char * ...@@ -243,10 +240,6 @@ mrb_debug_set_break_method( mrb_state *mrb, mrb_debug_context *dbg, const char *
if(class_name != NULL) { if(class_name != NULL) {
set_class = mrb_malloc(mrb, strlen(class_name) + 1); set_class = mrb_malloc(mrb, strlen(class_name) + 1);
if(set_class == NULL) {
return MRB_DEBUG_NOBUF;
}
strncpy(set_class, class_name, strlen(class_name) + 1); strncpy(set_class, class_name, strlen(class_name) + 1);
} }
else { else {
...@@ -254,12 +247,6 @@ mrb_debug_set_break_method( mrb_state *mrb, mrb_debug_context *dbg, const char * ...@@ -254,12 +247,6 @@ mrb_debug_set_break_method( mrb_state *mrb, mrb_debug_context *dbg, const char *
} }
set_method = mrb_malloc(mrb, strlen(method_name) + 1); set_method = mrb_malloc(mrb, strlen(method_name) + 1);
if(set_method == NULL) {
if(set_class != NULL) {
mrb_free(mrb, (void*)set_class);
}
return MRB_DEBUG_NOBUF;
}
strncpy(set_method, method_name, strlen(method_name) + 1); strncpy(set_method, method_name, strlen(method_name) + 1);
......
...@@ -48,7 +48,7 @@ build_path(mrb_state *mrb, const char *dir, const char *base) ...@@ -48,7 +48,7 @@ build_path(mrb_state *mrb, const char *dir, const char *base)
len += strlen(dir) + strlen("/"); len += strlen(dir) + strlen("/");
} }
if ((path = mrb_malloc(mrb, len)) != NULL) { path = mrb_malloc(mrb, len);
memset(path, 0, len); memset(path, 0, len);
if (strcmp(dir, ".")) { if (strcmp(dir, ".")) {
...@@ -56,7 +56,7 @@ build_path(mrb_state *mrb, const char *dir, const char *base) ...@@ -56,7 +56,7 @@ build_path(mrb_state *mrb, const char *dir, const char *base)
strcat(path, "/"); strcat(path, "/");
} }
strcat(path, base); strcat(path, base);
}
return path; return path;
} }
...@@ -73,10 +73,10 @@ dirname(mrb_state *mrb, const char *path) ...@@ -73,10 +73,10 @@ dirname(mrb_state *mrb, const char *path)
p = strrchr(path, '/'); p = strrchr(path, '/');
len = p != NULL ? p - path : strlen(path); len = p != NULL ? p - path : strlen(path);
if ((dir = mrb_malloc(mrb, len + 1)) != NULL) { dir = mrb_malloc(mrb, len + 1);
strncpy(dir, path, len); strncpy(dir, path, len);
dir[len] = '\0'; dir[len] = '\0';
}
return dir; return dir;
} }
...@@ -85,9 +85,7 @@ source_file_new(mrb_state *mrb, mrb_debug_context *dbg, char *filename) ...@@ -85,9 +85,7 @@ source_file_new(mrb_state *mrb, mrb_debug_context *dbg, char *filename)
{ {
source_file *file = NULL; source_file *file = NULL;
if ((file = mrb_malloc(mrb, sizeof(source_file))) == NULL) { file = mrb_malloc(mrb, sizeof(source_file));
return NULL;
}
memset(file, '\0', sizeof(source_file)); memset(file, '\0', sizeof(source_file));
file->fp = fopen(filename, "rb"); file->fp = fopen(filename, "rb");
......
...@@ -255,11 +255,11 @@ replace_ext(mrb_state *mrb, const char *filename, const char *ext) ...@@ -255,11 +255,11 @@ replace_ext(mrb_state *mrb, const char *filename, const char *ext)
len = strlen(filename); len = strlen(filename);
} }
if ((s = mrb_malloc(mrb, len + strlen(ext) + 1)) != NULL) { s = mrb_malloc(mrb, len + strlen(ext) + 1);
memset(s, '\0', len + strlen(ext) + 1); memset(s, '\0', len + strlen(ext) + 1);
strncpy(s, filename, len); strncpy(s, filename, len);
strcat(s, ext); strcat(s, ext);
}
return s; return s;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment