[PATCH 5/9] qi-fix-strncpy.patch
Dale Schumacher
dale.schumacher at gmail.com
Sat Sep 27 05:09:42 CEST 2008
On Fri, Sep 26, 2008 at 7:55 AM, Andy Green <andy at openmoko.com> wrote:
> Mini strncpy patch was buggy.
>
> Signed-off-by: Andy Green <andy at openmoko.com>
> ---
>
> src/utils.c | 3 +++
> 1 files changed, 3 insertions(+), 0 deletions(-)
>
> diff --git a/src/utils.c b/src/utils.c
> index 7e92288..dce53a3 100644
> --- a/src/utils.c
> +++ b/src/utils.c
> @@ -59,6 +59,9 @@ char *strncpy(char *dest, const char *src, size_t n)
> while (*src && n--)
> *dest++ = *src++;
>
> + if (n)
> + *dest = '\0';
> +
> return dest_orig;
> }
If you test the count _before_ you copy each character, you can avoid
the special case, like this:
while ((n--) && (*dest++ = *src++))
;
return dest_orig;
More information about the openmoko-kernel
mailing list