This is the mail archive of the
newlib@sourceware.org
mailing list for the newlib project.
Re: [PATCH] Fix padding in strncpy
- From: Jeff Johnston <jjohnstn at redhat dot com>
- To: Kazunori Asayama <asayama at sm dot sony dot co dot jp>
- Cc: newlib at sources dot redhat dot com
- Date: Mon, 04 Dec 2006 12:29:23 -0500
- Subject: Re: [PATCH] Fix padding in strncpy
- References: <20061204.145616.55909426.asayama@echo.sm.sony.co.jp>
Patch checked in.
-- Jeff J.
Kazunori Asayama wrote:
Attached is a patch to fix the following bug:
- SPU strncpy does not pad the end of destination area.
2006-12-04 Kazunori Asayama <asayama@sm.sony.co.jp>
* libc/machine/spu/strncpy.c: Add padding.
Index: newlib/newlib/libc/machine/spu/strncpy.c
===================================================================
--- newlib.orig/newlib/libc/machine/spu/strncpy.c
+++ newlib/newlib/libc/machine/spu/strncpy.c
@@ -76,6 +76,11 @@ char * strncpy(char * __restrict__ dest,
*/
len = spu_extract(spu_sel(spu_promote((unsigned int)len, 0), N, gt), 0);
+ /* Padding
+ */
+ if (len != n) {
+ memset(dest + len, 0, n - len);
+ }
/* Perform a memcpy of the resulting length
*/
return ((char *)memcpy((void *)dest, (const void *)src, len));