Skip to content

Commit ea80db6

Browse files
alejandro-colomarhallyn
authored andcommitted
lib/string/strchr/: strnul(): Simplify implementation
This avoids an __auto_type local variable, and a GNU statement expression. Reviewed-by: Kees Cook <kees@kernel.org> Signed-off-by: Alejandro Colomar <alx@kernel.org>
1 parent 25d44fc commit ea80db6

File tree

1 file changed

+3
-11
lines changed

1 file changed

+3
-11
lines changed

lib/string/strchr/strnul.h

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// SPDX-FileCopyrightText: 2024, Alejandro Colomar <alx@kernel.org>
1+
// SPDX-FileCopyrightText: 2024-2026, Alejandro Colomar <alx@kernel.org>
22
// SPDX-License-Identifier: BSD-3-Clause
33

44

@@ -10,17 +10,9 @@
1010

1111
#include <string.h>
1212

13-
#include "attr.h"
1413

15-
16-
// string null-byte
17-
// Similar to strlen(3), but return a pointer instead of an offset.
18-
#define strnul(s) \
19-
({ \
20-
__auto_type s_ = s; \
21-
\
22-
s_ + strlen(s_); \
23-
})
14+
// strnul - string null-byte
15+
#define strnul(s) strchr(s, '\0')
2416

2517

2618
#endif // include guard

0 commit comments

Comments
 (0)