[PATCH] Fix padding in strncpy
Kazunori Asayama
asayama@sm.sony.co.jp
Mon Dec 4 17:27:00 GMT 2006
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));
More information about the Newlib
mailing list