Skip to content

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

Closed

Description

@rainerjung

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

Activity

  1. devnexen commented on Dec 22, 2023

    @devnexen
    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.

  2. self-assigned this
    on Dec 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions