From abe43f42627868d7ed3f73900a47be56615bc247 Mon Sep 17 00:00:00 2001 From: Jeff Johnston Date: Mon, 9 Apr 2007 16:03:26 +0000 Subject: [PATCH] 2007-04-09 Joel Schopp * 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. --- newlib/ChangeLog | 7 +++++++ newlib/libc/machine/spu/strxfrm.c | 11 +++-------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/newlib/ChangeLog b/newlib/ChangeLog index 5b0b6ba27..cccd78a7d 100644 --- a/newlib/ChangeLog +++ b/newlib/ChangeLog @@ -1,3 +1,10 @@ +2007-04-09 Joel Schopp + + * 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. + 2007-04-04 Mark Mitchell * libc/stdlib/__call_atexit.c (__call_exitprocs): Handle atexit diff --git a/newlib/libc/machine/spu/strxfrm.c b/newlib/libc/machine/spu/strxfrm.c index 6d449edf0..02bb9a8ec 100644 --- a/newlib/libc/machine/spu/strxfrm.c +++ b/newlib/libc/machine/spu/strxfrm.c @@ -34,6 +34,7 @@ #include #include +#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, const char * __restrict__ src, size_t n 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; }