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 for strcat and strncat on the SPU


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


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