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]

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


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;
 }


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