doc: update HACKING wrt strncpy/pstrcpy

Reword the section on strncpy: its NUL-filling is important
in some cases.  Mention that pstrcpy's signature is different.

Signed-off-by: Jim Meyering <meyering@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit is contained in:
Jim Meyering 2012-10-04 13:10:03 +02:00 committed by Anthony Liguori
parent 9310b9be14
commit 9b9e3ec1b4
1 changed files with 5 additions and 4 deletions

View File

@ -91,10 +91,11 @@ emulators.
4. String manipulation 4. String manipulation
Do not use the strncpy function. According to the man page, it does Do not use the strncpy function. As mentioned in the man page, it does *not*
*not* guarantee a NULL-terminated buffer, which makes it extremely dangerous guarantee a NULL-terminated buffer, which makes it extremely dangerous to use.
to use. Instead, use functionally equivalent function: It also zeros trailing destination bytes out to the specified length. Instead,
void pstrcpy(char *buf, int buf_size, const char *str) use this similar function when possible, but note its different signature:
void pstrcpy(char *dest, int dest_buf_size, const char *src)
Don't use strcat because it can't check for buffer overflows, but: Don't use strcat because it can't check for buffer overflows, but:
char *pstrcat(char *buf, int buf_size, const char *s) char *pstrcat(char *buf, int buf_size, const char *s)