[patch] SPU strncpy fix

Jeff Johnston jjohnstn@redhat.com
Thu Jul 17 20:32:00 GMT 2008


Yes, go ahead.

-- Jeff J.

Ken Werner wrote:
> Hi,
>
> according to the C standard strncpy should pad null bytes if the length of 
> the "src" string is less than "n". Ok to Apply?
>
> Ken
>
> newlib/ChangeLog:
>
> 2008-07-17  Ken Werner  <ken.werner@de.ibm.com>
>
>         * libc/machine/spu/strcpy.h: Pad null bytes if necessary.
>
> Index: src/newlib/libc/machine/spu/strcpy.h
> ===================================================================
> --- src.orig/newlib/libc/machine/spu/strcpy.h
> +++ src/newlib/libc/machine/spu/strcpy.h
> @@ -176,5 +176,9 @@ static inline void * _strncpy(char * __r
>       */
>      dest[maxlen - spu_extract(curlen, 0)] = '\0';
>    }
> +
> +  /* Pad null bytes if the length of the "src" is less than "n" (strncpy).  
> */
> +  if (checklen && !lastzero && (maxlen != spu_extract(curlen,0)))
> +    memset(dest + spu_extract(curlen, 0), 0, maxlen - spu_extract(curlen, 
> 0));
>    return (dest);
>  }
>   



More information about the Newlib mailing list