Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F177455712
D61401.1794449243.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
3 KB
Referenced Files
None
Subscribers
None
D61401.1794449243.diff
View Options
diff --git a/sys/sys/cdefs.h b/sys/sys/cdefs.h
--- a/sys/sys/cdefs.h
+++ b/sys/sys/cdefs.h
@@ -389,9 +389,13 @@
#define __sized_by_or_null(N) __attribute__((__sized_by_or_null__(N)))
/* Pointer bounded by the sibling pointer E (one past the end). */
#define __ended_by(E) __attribute__((__ended_by__(E)))
+/* Pointer to an array ending at the first zero element. */
+#define __null_terminated __attribute__((__terminated_by__(0)))
/* Escape hatches: produce a checked pointer from an address (and size). */
#define __unsafe_forge_single(T, P) \
((T __single)__builtin_unsafe_forge_single((P)))
+#define __unsafe_forge_null_terminated(T, P) \
+ ((T __null_terminated)__builtin_unsafe_forge_terminated_by((P), 0))
/* Set the default ABI for subsequent unannotated pointers in this file. */
#define __ptrcheck_abi_assume_single() \
_Pragma("clang abi_ptr_attr set(single)")
@@ -428,7 +432,9 @@
#define __sized_by(N)
#define __sized_by_or_null(N)
#define __ended_by(E)
+#define __null_terminated
#define __unsafe_forge_single(T, P) ((T)(P))
+#define __unsafe_forge_null_terminated(T, P) ((T)(P))
#define __unsafe_forge_bidi_indexable(T, P, S) ((void)(S), (T)(P))
#define __ptrcheck_abi_assume_single()
#define __ptrcheck_abi_assume_unsafe_indexable()
diff --git a/sys/sys/hash.h b/sys/sys/hash.h
--- a/sys/sys/hash.h
+++ b/sys/sys/hash.h
@@ -43,11 +43,12 @@
* the previous hash.
*/
static __inline uint32_t
-hash32_buf(const void *buf, size_t len, uint32_t hash)
+hash32_buf(const void * __sized_by(len) buf, size_t len, uint32_t hash)
{
const unsigned char *p = buf;
+ size_t n = len;
- while (len--)
+ while (n--)
hash = HASHSTEP(hash, *p++);
return hash;
@@ -59,7 +60,8 @@
static __inline uint32_t
hash32_str(const void *buf, uint32_t hash)
{
- const unsigned char *p = buf;
+ const unsigned char * __null_terminated p =
+ __unsafe_forge_null_terminated(const unsigned char *, buf);
while (*p)
hash = HASHSTEP(hash, *p++);
@@ -73,7 +75,8 @@
static __inline uint32_t
hash32_strn(const void *buf, size_t len, uint32_t hash)
{
- const unsigned char *p = buf;
+ const unsigned char * __null_terminated p =
+ __unsafe_forge_null_terminated(const unsigned char *, buf);
while (*p && len--)
hash = HASHSTEP(hash, *p++);
@@ -89,13 +92,14 @@
static __inline uint32_t
hash32_stre(const void *buf, int end, const char **ep, uint32_t hash)
{
- const unsigned char *p = buf;
+ const unsigned char * __null_terminated p =
+ __unsafe_forge_null_terminated(const unsigned char *, buf);
while (*p && (*p != end))
hash = HASHSTEP(hash, *p++);
if (ep)
- *ep = p;
+ *ep = (const char * __null_terminated)p;
return hash;
}
@@ -109,13 +113,14 @@
hash32_strne(const void *buf, size_t len, int end, const char **ep,
uint32_t hash)
{
- const unsigned char *p = buf;
+ const unsigned char * __null_terminated p =
+ __unsafe_forge_null_terminated(const unsigned char *, buf);
while (*p && (*p != end) && len--)
hash = HASHSTEP(hash, *p++);
if (ep)
- *ep = p;
+ *ep = (const char * __null_terminated)p;
return hash;
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Nov 12, 2:07 AM (10 h, 10 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
41664561
Default Alt Text
D61401.1794449243.diff (3 KB)
Attached To
Mode
D61401: sys: add __null_terminated and bound the hash.h helpers
Attached
Detach File
Event Timeline