diff options
author | Thejaswani Putta <thejaswani.putta@intel.com> | 2019-04-11 18:36:08 -0700 |
---|---|---|
committer | Patrick Georgi <pgeorgi@google.com> | 2019-04-23 09:56:37 +0000 |
commit | 6f5225c7e0ad7a373af1decc212cde5c33b00730 (patch) | |
tree | 794593f84299c9258953eb34fdd39ecee39a1f20 /src/lib | |
parent | 21f9b3ecd7babefa51f497bd61495316ebf41851 (diff) |
Klocwork: Fix the Null pointer derefernce found by klocwork
Signed-off-by: Thejaswani Putta <thejaswani.putta@intel.com>
Change-Id: I15973ac28e9645826986cf63d2160eedb83024e4
Reviewed-on: https://review.coreboot.org/c/coreboot/+/32290
Reviewed-by: Julius Werner <jwerner@chromium.org>
Reviewed-by: Lijian Zhao <lijian.zhao@intel.com>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/string.c | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/src/lib/string.c b/src/lib/string.c index df2fd80849..2e71489ff6 100644 --- a/src/lib/string.c +++ b/src/lib/string.c @@ -6,7 +6,8 @@ char *strdup(const char *s) { size_t sz = strlen(s) + 1; char *d = malloc(sz); - memcpy(d, s, sz); + if (d) + memcpy(d, s, sz); return d; } @@ -15,7 +16,9 @@ char *strconcat(const char *s1, const char *s2) size_t sz_1 = strlen(s1); size_t sz_2 = strlen(s2); char *d = malloc(sz_1 + sz_2 + 1); - memcpy(d, s1, sz_1); - memcpy(d + sz_1, s2, sz_2 + 1); + if (d) { + memcpy(d, s1, sz_1); + memcpy(d + sz_1, s2, sz_2 + 1); + } return d; } |