From b37182eb01e20e28b78bc65033b01a51c658e2fc Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sun, 10 Jan 2010 21:39:12 +0100 Subject: [PATCH] unistr/u*-stpncpy: Fix the return value. --- ChangeLog | 8 ++++++++ lib/unistr.h | 4 ++-- lib/unistr/u-stpncpy.h | 10 +++++++--- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6a46d149f2..f1f514a129 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2010-01-10 Bruno Haible + + unistr/u*-stpncpy: Fix the return value. + * lib/unistr.h (u8_stpncpy, u16_stpncpy, u32_stpncpy): Make the + description of the return value consistent with stpncpy in glibc. + * lib/unistr/u-stpncpy.h (FUNC): Return the pointer past the last + written non-NUL unit. + 2010-01-10 Bruno Haible unistr/u*-next: Add missing dependencies. diff --git a/lib/unistr.h b/lib/unistr.h index 1cdf3a8a60..26a3e33e45 100644 --- a/lib/unistr.h +++ b/lib/unistr.h @@ -529,8 +529,8 @@ extern uint16_t * extern uint32_t * u32_strncpy (uint32_t *dest, const uint32_t *src, size_t n); -/* Copy no more than N units of SRC to DEST, returning the address of - the last unit written into DEST. */ +/* Copy no more than N units of SRC to DEST. Return a pointer past the last + non-NUL unit written into DEST. */ /* Similar to stpncpy(). */ extern uint8_t * u8_stpncpy (uint8_t *dest, const uint8_t *src, size_t n); diff --git a/lib/unistr/u-stpncpy.h b/lib/unistr/u-stpncpy.h index 335a8519d8..4d6dd3c701 100644 --- a/lib/unistr/u-stpncpy.h +++ b/lib/unistr/u-stpncpy.h @@ -23,8 +23,12 @@ FUNC (UNIT *dest, const UNIT *src, size_t n) /* This behavior is rarely useful, but it is here for consistency with strncpy and wcsncpy. */ - for (; n > 0; n--) - *dest++ = 0; + { + UNIT *destptr = dest; - return dest - 1; + for (; n > 0; n--) + *destptr++ = 0; + } + + return dest; } -- 2.30.2