summaryrefslogtreecommitdiff
path: root/src/lib/libc/string/strnlen.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libc/string/strnlen.c')
-rw-r--r--src/lib/libc/string/strnlen.c9
1 files changed, 2 insertions, 7 deletions
diff --git a/src/lib/libc/string/strnlen.c b/src/lib/libc/string/strnlen.c
index 33c3b6e2ca..db809756ac 100644
--- a/src/lib/libc/string/strnlen.c
+++ b/src/lib/libc/string/strnlen.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: strnlen.c,v 1.7 2016/10/14 18:19:04 dtucker Exp $ */ 1/* $OpenBSD: strnlen.c,v 1.8 2016/10/16 17:37:39 dtucker Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2010 Todd C. Miller <Todd.Miller@courtesan.com> 4 * Copyright (c) 2010 Todd C. Miller <Todd.Miller@courtesan.com>
@@ -19,7 +19,6 @@
19#include <sys/types.h> 19#include <sys/types.h>
20 20
21#include <string.h> 21#include <string.h>
22#include <stdint.h>
23 22
24size_t 23size_t
25strnlen(const char *str, size_t maxlen) 24strnlen(const char *str, size_t maxlen)
@@ -29,10 +28,6 @@ strnlen(const char *str, size_t maxlen)
29 for (cp = str; maxlen != 0 && *cp != '\0'; cp++, maxlen--) 28 for (cp = str; maxlen != 0 && *cp != '\0'; cp++, maxlen--)
30 ; 29 ;
31 30
32 /* 31 return (size_t)(cp - str);
33 * Cast pointers to unsigned type before calculation, to avoid signed
34 * overflow when the string ends where the MSB has changed.
35 */
36 return (size_t)((uintptr_t)cp - (uintptr_t)str);
37} 32}
38DEF_WEAK(strnlen); 33DEF_WEAK(strnlen);