diff options
Diffstat (limited to '')
| -rw-r--r-- | src/lib/libc/string/strlcpy.c | 10 | 
1 files changed, 8 insertions, 2 deletions
diff --git a/src/lib/libc/string/strlcpy.c b/src/lib/libc/string/strlcpy.c index 5fcf084aaa..f282834680 100644 --- a/src/lib/libc/string/strlcpy.c +++ b/src/lib/libc/string/strlcpy.c  | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: strlcpy.c,v 1.13 2015/08/31 02:53:57 guenther Exp $ */ | 1 | /* $OpenBSD: strlcpy.c,v 1.14 2016/10/14 18:19:04 dtucker Exp $ */ | 
| 2 | 2 | ||
| 3 | /* | 3 | /* | 
| 4 | * Copyright (c) 1998, 2015 Todd C. Miller <Todd.Miller@courtesan.com> | 4 | * Copyright (c) 1998, 2015 Todd C. Miller <Todd.Miller@courtesan.com> | 
| @@ -18,6 +18,7 @@ | |||
| 18 | 18 | ||
| 19 | #include <sys/types.h> | 19 | #include <sys/types.h> | 
| 20 | #include <string.h> | 20 | #include <string.h> | 
| 21 | #include <stdint.h> | ||
| 21 | 22 | ||
| 22 | /* | 23 | /* | 
| 23 | * Copy string src to buffer dst of size dsize. At most dsize-1 | 24 | * Copy string src to buffer dst of size dsize. At most dsize-1 | 
| @@ -46,6 +47,11 @@ strlcpy(char *dst, const char *src, size_t dsize) | |||
| 46 | ; | 47 | ; | 
| 47 | } | 48 | } | 
| 48 | 49 | ||
| 49 | return(src - osrc - 1); /* count does not include NUL */ | 50 | /* | 
| 51 | * Cast pointers to unsigned type before calculation, to avoid signed | ||
| 52 | * overflow when the string ends where the MSB has changed. | ||
| 53 | * Return value does not include NUL. | ||
| 54 | */ | ||
| 55 | return((uintptr_t)src - (uintptr_t)osrc - 1); | ||
| 50 | } | 56 | } | 
| 51 | DEF_WEAK(strlcpy); | 57 | DEF_WEAK(strlcpy); | 
