This is the mail archive of the
newlib@sourceware.org
mailing list for the newlib project.
[PATCH] Fix padding in strncpy
- From: Kazunori Asayama <asayama at sm dot sony dot co dot jp>
- To: newlib at sources dot redhat dot com
- Date: Mon, 04 Dec 2006 14:56:16 +0900 (LMT)
- Subject: [PATCH] Fix padding in strncpy
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));