[PATCH] Fix the spu specific strxfrm to match generic newlib and glibc

Patrick Mansfield patmans@us.ibm.com
Fri Apr 6 15:55:00 GMT 2007


Jeff - can you please apply this fix?

Fix the spu specific strxfrm so that when the length of the src string is
greater than or equal to the passed in argument n we still copy over n
bytes.

This matches the current glibc and the generic newlib strxfrm behaviour.

newlib ChangeLog:

2007-04-06  Patrick Mansfield <patmans@us.ibm.com>
  
	* libc/machine/spu/strxfrm.c: Fix strxfrm so we still copy data
	even if the passed in length n is shorter than the source string.
	This matches both the non-spu specific and the glibc strxfrm
	behaviour.

Index: my-base-quilt/newlib/libc/machine/spu/strxfrm.c
===================================================================
--- my-base-quilt.orig/newlib/libc/machine/spu/strxfrm.c
+++ my-base-quilt/newlib/libc/machine/spu/strxfrm.c
@@ -34,6 +34,7 @@
 #include <stddef.h>
 #include <string.h>
 
+#define min(a, b)  (a) < (b) ? (a) : (b)
 
 /* The strxfrm() function transforms the src string into a form such that
  * the result of strcmp() on two strings that have been transformed with
@@ -54,13 +55,7 @@ size_t strxfrm(char * __restrict__ dest,
   size_t len;
 
   len = strlen(src);
+  (void)memcpy((void *)dest, (void *)src, min(n,len + 1));
 
-  /* Since the destination is indeterminant if n is less than of equal
-   * to the string length, we skip performing the copy (altogether) in
-   * this case.
-   */
-  if (n > len) {
-    (void)memcpy((void *)dest, (void *)src, n);
-  }
-  return (len);
+  return len;
 }



More information about the Newlib mailing list