Skip to content

PHP 8.3: memchr needs explicit cast if strnlen not available #12999

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
rainerjung opened this issue Dec 22, 2023 · 1 comment
Closed

PHP 8.3: memchr needs explicit cast if strnlen not available #12999

rainerjung opened this issue Dec 22, 2023 · 1 comment

Comments

@rainerjung
Copy link

Description

This is a build problem:

.../Zend/zend_operators.h: In function 'size_t zend_strnlen(const char*, size_t)':
.../Zend/zend_operators.h:272:24: error: invalid conversion from 'const void*' to 'const char*' [-fpermissive]
  272 |  const char *p = memchr(s, '\0', maxlen);
      |                  ~~~~~~^~~~~~~~~~~~~~~~~
      |                        |
      |                        const void*

This code is only compiled if HAVE_STRNLEN is not defined. So it is not compiled e.g. on Linux, but on Solaris 10.

A simple patch to fix this is:

--- Zend/zend_operators.h	2023-12-20 13:44:38.000000000 +0100
+++ Zend/zend_operators.h	2023-12-22 13:23:35.110296202 +0100
@@ -269,7 +269,7 @@
 #if defined(HAVE_STRNLEN)
 	return strnlen(s, maxlen);
 #else
-	const char *p = memchr(s, '\0', maxlen);
+	const char *p = (const char *)memchr(s, '\0', maxlen);
 	return p ? p-s : maxlen;
 #endif
 }

Note, that this pattern is already used in the same file in several places that use memchr. Just not in this one line which gets only conditionally compiled.

Please don't force me to make a pull request for this trivial change. Thanks!

PHP Version

PHP 8.3.1

Operating System

Solaris 10

@devnexen
Copy link
Member

Please don't force me to make a pull request for this trivial change. Thanks!

Missed this bit :) fair enough I ll make a PR thanks for your report.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants