aboutsummaryrefslogtreecommitdiffstats
path: root/dir.c
diff options
context:
space:
mode:
authorYusuke Endoh <mame@ruby-lang.org>2019-10-13 00:51:50 +0900
committerYusuke Endoh <mame@ruby-lang.org>2019-10-13 00:51:50 +0900
commita5ecf7e0a165dff1b4604f1ed75a677c690488df (patch)
tree5bb23953c4fffab7edd6d06cc451ad21a9d9d2b4 /dir.c
parent90b9900dc159efb63feee9b0995cc5d56aef6d75 (diff)
downloadruby-a5ecf7e0a165dff1b4604f1ed75a677c690488df.tar.gz
dir.c (join_path_from_pattern): check NULL from malloc
Coverity Scan points out that all the return values of GLOB_ALLOC_N are NULL-checked except this call.
Diffstat (limited to 'dir.c')
-rw-r--r--dir.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/dir.c b/dir.c
index e98fa25278..5221490b44 100644
--- a/dir.c
+++ b/dir.c
@@ -2072,8 +2072,10 @@ join_path_from_pattern(struct glob_pattern **beg)
if (!path) {
path_len = strlen(str);
path = GLOB_ALLOC_N(char, path_len + 1);
- memcpy(path, str, path_len);
- path[path_len] = '\0';
+ if (path) {
+ memcpy(path, str, path_len);
+ path[path_len] = '\0';
+ }
}
else {
size_t len = strlen(str);