This is the mail archive of the newlib@sourceware.org mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [patch] SPU strncpy fix


Yes, go ahead.

-- Jeff J.

Ken Werner wrote:
Hi,

according to the C standard strncpy should pad null bytes if the length of the "src" string is less than "n". Ok to Apply?

Ken

newlib/ChangeLog:

2008-07-17 Ken Werner <ken.werner@de.ibm.com>

* libc/machine/spu/strcpy.h: Pad null bytes if necessary.

Index: src/newlib/libc/machine/spu/strcpy.h
===================================================================
--- src.orig/newlib/libc/machine/spu/strcpy.h
+++ src/newlib/libc/machine/spu/strcpy.h
@@ -176,5 +176,9 @@ static inline void * _strncpy(char * __r
*/
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);
}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]