From eb19b8f95a6a22ade6911ac98d1a76313ec99f53 Mon Sep 17 00:00:00 2001 From: Jeff Johnston Date: Thu, 17 Jul 2008 19:00:44 +0000 Subject: [PATCH] 2008-07-17 Ken Werner * libc/machine/spu/strcpy.h: Pad null bytes if necessary. --- newlib/ChangeLog | 4 ++++ newlib/libc/machine/spu/strcpy.h | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/newlib/ChangeLog b/newlib/ChangeLog index 2d4f76eef..7b93e69d1 100644 --- a/newlib/ChangeLog +++ b/newlib/ChangeLog @@ -1,3 +1,7 @@ +2008-07-17 Ken Werner + + * libc/machine/spu/strcpy.h: Pad null bytes if necessary. + 2008-07-08 Kenji Tanaka * libc/machine/mn10300/memset.S: Fix bug where return value is diff --git a/newlib/libc/machine/spu/strcpy.h b/newlib/libc/machine/spu/strcpy.h index e2ec2b259..946148bd2 100644 --- a/newlib/libc/machine/spu/strcpy.h +++ b/newlib/libc/machine/spu/strcpy.h @@ -176,5 +176,9 @@ static inline void * _strncpy(char * __restrict__ dest, const char * */ dest[maxlen - spu_extract(curlen, 0)] = '\0'; } + + /* Pad null bytes if the length of the "src" is less than "n" (strncpy). */ + if (checklen && !lastzero && (maxlen != spu_extract(curlen,0))) + memset(dest + spu_extract(curlen, 0), 0, maxlen - spu_extract(curlen, 0)); return (dest); }