libs/libc/string/lib_stpncpy.c: Correct the return poineter value for the case where the NUL terminator is transferred.

This commit is contained in:
Gregory Nutt 2018-09-18 06:43:10 -06:00
parent 68d4c1d4ed
commit 3950398841
2 changed files with 15 additions and 8 deletions

View File

@ -63,8 +63,8 @@
* the string pointed to by the message argument will be written,
* followed by a colon and a space.
*
* Then the signal description string associated with signum or with the
* signal indicated by pinfo will be written, followed by a newline.
* Then the signal description string associated with signum will be
* written, followed by a newline.
*
* Returned Value
* None. The errno value is never set in this implementation.
@ -99,8 +99,8 @@ void psignal(int signum, FAR const char *message)
* the string pointed to by the message argument will be written,
* followed by a colon and a space.
*
* Then the signal description string associated with signum or with the
* signal indicated by pinfo will be written, followed by a newline.
* Then the signal description string associated with the signal
* indicated by pinfo will be written, followed by a newline.
*
* Returned Value
* None. Since no value is returned, an application wishing to check for
@ -121,4 +121,4 @@ void psiginfo(FAR const siginfo_t *pinfo, FAR const char *message)
}
}
#endif /* __KERNEL__ */
#endif /* !__KERNEL__ */

View File

@ -78,17 +78,24 @@ FAR char *strncpy(FAR char *dest, FAR const char *src, size_t n)
* encountered.
*/
while ((dest != end) && (*dest++ = *src++) != '\0')
while ((dest != end) && (*dest = *src++) != '\0')
{
/* Increment the 'dest' pointer only if it does not refer to the
* NUL terminator.
*/
dest++;
}
/* Return the pointer to the NUL terminator (or to the end of the buffer
* + 1.
* + 1).
*/
ret = dest;
/* Pad the remainder of the array pointer to 'dest' with NULs */
/* Pad the remainder of the array pointer to 'dest' with NULs. This
* overwrites any previously copied NUL terminator.
*/
while (dest != end)
{