diff options
Diffstat (limited to 'libbb/safe_strncpy.c')
-rw-r--r-- | libbb/safe_strncpy.c | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/libbb/safe_strncpy.c b/libbb/safe_strncpy.c index add92ac9f..42bc16ea0 100644 --- a/libbb/safe_strncpy.c +++ b/libbb/safe_strncpy.c | |||
@@ -15,6 +15,7 @@ | |||
15 | /* Like strncpy but make sure the resulting string is always 0 terminated. */ | 15 | /* Like strncpy but make sure the resulting string is always 0 terminated. */ |
16 | char * safe_strncpy(char *dst, const char *src, size_t size) | 16 | char * safe_strncpy(char *dst, const char *src, size_t size) |
17 | { | 17 | { |
18 | dst[size-1] = '\0'; | 18 | if (!size) return dst; |
19 | return strncpy(dst, src, size-1); | 19 | dst[--size] = '\0'; |
20 | return strncpy(dst, src, size); | ||
20 | } | 21 | } |