libpayload: Add the null terminator to the end of the duplicated string
authorJordan Crouse <jordan.crouse@amd.com>
Fri, 25 Apr 2008 23:07:39 +0000 (23:07 +0000)
committerJordan Crouse <jordan.crouse@amd.com>
Fri, 25 Apr 2008 23:07:39 +0000 (23:07 +0000)
Signed-off-by: Jordan Crouse <jordan.crouse@amd.com>
Acked-by: Myles Watson <mylesgw@gmail.com>
git-svn-id: svn://svn.coreboot.org/coreboot/trunk@3268 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1

payloads/libpayload/libc/string.c

index 1e9b8bc01ca2889effbf48086b26ca8f15ad4329..e86f2c924ae5bcbcb5ded866e15f6ee2b963ff10 100644 (file)
@@ -173,11 +173,12 @@ char *strchr(const char *s, int c)
 char *strdup(const char *s)
 {
        int n = strlen(s);
-       char *p = malloc(n);
+       char *p = malloc(n + 1);
 
        if (p != NULL)
                strncpy(p, s, n);
 
+       p[n] = 0;
        return p;
 }