coreboot-kgpe-d16/src/lib/string.c
Thejaswani Putta 6f5225c7e0 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>
2019-04-23 09:56:37 +00:00

24 lines
407 B
C

#include <string.h>
#include <stddef.h>
#include <stdlib.h>
char *strdup(const char *s)
{
size_t sz = strlen(s) + 1;
char *d = malloc(sz);
if (d)
memcpy(d, s, sz);
return d;
}
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);
if (d) {
memcpy(d, s1, sz_1);
memcpy(d + sz_1, s2, sz_2 + 1);
}
return d;
}