[patch] fix for strcat and strncat on the SPU

Ken Werner ken@linux.vnet.ibm.com
Mon Jun 9 10:04:00 GMT 2008


Hi,

the SPU implementation of strcat and strncat modifies the dst pointer. The 
following test would return SIGABRT on the SPU if build with -fno-builtin:
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
int main (int argc, char* argv[])
{
  char dst[64];
  strcpy (dst, "hello world");
  if (strcat (dst, "foo") != dst)
    abort ();
  return 0;
}

This patch fixes that. Ok to apply?

Ken

newlib/ChangeLog:

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

        * libc/machine/spu/strcat.c: Return value fixed.
        * libc/machine/spu/strncat.c: Likewise.

Index: src/newlib/libc/machine/spu/strcat.c
===================================================================
--- src.orig/newlib/libc/machine/spu/strcat.c
+++ src/newlib/libc/machine/spu/strcat.c
@@ -41,5 +41,7 @@
  */
 char *strcat(char * __restrict__ dest, const char * __restrict__ src)
 {
-  return _strncpy(_straddr(dest), src, 0, 0, 0);
+  char *ret = dest;
+  _strncpy(_straddr(dest), src, 0, 0, 0);
+  return ret;
 }
Index: src/newlib/libc/machine/spu/strncat.c
===================================================================
--- src.orig/newlib/libc/machine/spu/strncat.c
+++ src/newlib/libc/machine/spu/strncat.c
@@ -41,5 +41,7 @@
 char * strncat(char * __restrict__ dest, const char * __restrict__ src,
                size_t n)
 {
-  return _strncpy(_straddr(dest), src, n, 1, 1);
+  char *ret = dest;
+  _strncpy(_straddr(dest), src, n, 1, 1);
+  return ret;
 }



More information about the Newlib mailing list