[pushed] c++: don't use strchrnul [PR107781]

Message ID 20221122142955.677712-1-jason@redhat.com
State New
Headers
Series [pushed] c++: don't use strchrnul [PR107781] |

Commit Message

Jason Merrill Nov. 22, 2022, 2:29 p.m. UTC
  As Jonathan suggested.

Tested x86_64-pc-linux-gnu, applying to trunk.

-- 8< --

The contracts implementation was using strchrnul, which is a glibc
extension, so bootstrap broke on non-glibc targets.  Use C89 strcspn
instead.

	PR c++/107781

gcc/cp/ChangeLog:

	* contracts.cc (role_name_equal): Use strcspn instead
	of strchrnul.
---
 gcc/cp/contracts.cc | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)


base-commit: 4eb3a48698b2ca43967a4e7e7cfc0408192e85b2
  

Patch

diff --git a/gcc/cp/contracts.cc b/gcc/cp/contracts.cc
index f3afcc62ba0..a9097016768 100644
--- a/gcc/cp/contracts.cc
+++ b/gcc/cp/contracts.cc
@@ -210,8 +210,8 @@  lookup_concrete_semantic (const char *name)
 static bool
 role_name_equal (const char *role, const char *name)
 {
-  size_t role_len = strchrnul (role, ':') - role;
-  size_t name_len = strchrnul (name, ':') - name;
+  size_t role_len = strcspn (role, ":");
+  size_t name_len = strcspn (name, ":");
   if (role_len != name_len)
     return false;
   return strncmp (role, name, role_len) == 0;