From 88f126fc20ac7e26d2553331d549904f338fec55 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 21 Feb 2023 11:39:32 +0100 Subject: [PATCH 1/7] ext/opcache/zend_shared_alloc: make `error_in` strings const This allows using string literals without implicitly casting away the `const`. --- ext/opcache/shared_alloc_mmap.c | 2 +- ext/opcache/shared_alloc_posix.c | 2 +- ext/opcache/shared_alloc_shm.c | 2 +- ext/opcache/shared_alloc_win32.c | 4 ++-- ext/opcache/zend_shared_alloc.c | 6 +++--- ext/opcache/zend_shared_alloc.h | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/ext/opcache/shared_alloc_mmap.c b/ext/opcache/shared_alloc_mmap.c index 20fbc5144209..1414ef96149d 100644 --- a/ext/opcache/shared_alloc_mmap.c +++ b/ext/opcache/shared_alloc_mmap.c @@ -154,7 +154,7 @@ static void *find_prefered_mmap_base(size_t requested_size) } #endif -static int create_segments(size_t requested_size, zend_shared_segment ***shared_segments_p, int *shared_segments_count, char **error_in) +static int create_segments(size_t requested_size, zend_shared_segment ***shared_segments_p, int *shared_segments_count, const char **error_in) { zend_shared_segment *shared_segment; int flags = PROT_READ | PROT_WRITE, fd = -1; diff --git a/ext/opcache/shared_alloc_posix.c b/ext/opcache/shared_alloc_posix.c index c7489a247016..70391473dd9e 100644 --- a/ext/opcache/shared_alloc_posix.c +++ b/ext/opcache/shared_alloc_posix.c @@ -36,7 +36,7 @@ typedef struct { int shm_fd; } zend_shared_segment_posix; -static int create_segments(size_t requested_size, zend_shared_segment_posix ***shared_segments_p, int *shared_segments_count, char **error_in) +static int create_segments(size_t requested_size, zend_shared_segment_posix ***shared_segments_p, int *shared_segments_count, const char **error_in) { zend_shared_segment_posix *shared_segment; char shared_segment_name[sizeof("/ZendAccelerator.") + 20]; diff --git a/ext/opcache/shared_alloc_shm.c b/ext/opcache/shared_alloc_shm.c index 2764dffd5e43..09a357d189ed 100644 --- a/ext/opcache/shared_alloc_shm.c +++ b/ext/opcache/shared_alloc_shm.c @@ -50,7 +50,7 @@ typedef struct { int shm_id; } zend_shared_segment_shm; -static int create_segments(size_t requested_size, zend_shared_segment_shm ***shared_segments_p, int *shared_segments_count, char **error_in) +static int create_segments(size_t requested_size, zend_shared_segment_shm ***shared_segments_p, int *shared_segments_count, const char **error_in) { int i; size_t allocate_size = 0, remaining_bytes = requested_size, seg_allocate_size; diff --git a/ext/opcache/shared_alloc_win32.c b/ext/opcache/shared_alloc_win32.c index 97cae92ee2db..893fe98ec189 100644 --- a/ext/opcache/shared_alloc_win32.c +++ b/ext/opcache/shared_alloc_win32.c @@ -112,7 +112,7 @@ void zend_shared_alloc_unlock_win32(void) ReleaseMutex(memory_mutex); } -static int zend_shared_alloc_reattach(size_t requested_size, char **error_in) +static int zend_shared_alloc_reattach(size_t requested_size, const char **error_in) { int err; void *wanted_mapping_base; @@ -199,7 +199,7 @@ static int zend_shared_alloc_reattach(size_t requested_size, char **error_in) return SUCCESSFULLY_REATTACHED; } -static int create_segments(size_t requested_size, zend_shared_segment ***shared_segments_p, int *shared_segments_count, char **error_in) +static int create_segments(size_t requested_size, zend_shared_segment ***shared_segments_p, int *shared_segments_count, const char **error_in) { int err = 0, ret; zend_shared_segment *shared_segment; diff --git a/ext/opcache/zend_shared_alloc.c b/ext/opcache/zend_shared_alloc.c index 247e248cbc47..a374cf6f97de 100644 --- a/ext/opcache/zend_shared_alloc.c +++ b/ext/opcache/zend_shared_alloc.c @@ -97,7 +97,7 @@ void zend_shared_alloc_create_lock(char *lockfile_path) } #endif -static void no_memory_bailout(size_t allocate_size, char *error) +static void no_memory_bailout(size_t allocate_size, const char *error) { zend_accel_error_noreturn(ACCEL_LOG_FATAL, "Unable to allocate shared memory segment of %zu bytes: %s: %s (%d)", allocate_size, error?error:"unknown", strerror(errno), errno ); } @@ -117,7 +117,7 @@ static void copy_shared_segments(void *to, void *from, int count, int size) } } -static int zend_shared_alloc_try(const zend_shared_memory_handler_entry *he, size_t requested_size, zend_shared_segment ***shared_segments_p, int *shared_segments_count, char **error_in) +static int zend_shared_alloc_try(const zend_shared_memory_handler_entry *he, size_t requested_size, zend_shared_segment ***shared_segments_p, int *shared_segments_count, const char **error_in) { int res; g_shared_alloc_handler = he->handler; @@ -151,7 +151,7 @@ int zend_shared_alloc_startup(size_t requested_size, size_t reserved_size) zend_shared_segment **tmp_shared_segments; size_t shared_segments_array_size; zend_smm_shared_globals tmp_shared_globals, *p_tmp_shared_globals; - char *error_in = NULL; + const char *error_in = NULL; const zend_shared_memory_handler_entry *he; int res = ALLOC_FAILURE; int i; diff --git a/ext/opcache/zend_shared_alloc.h b/ext/opcache/zend_shared_alloc.h index 02d15e28a316..ac7ec3e33f34 100644 --- a/ext/opcache/zend_shared_alloc.h +++ b/ext/opcache/zend_shared_alloc.h @@ -80,7 +80,7 @@ typedef struct _zend_shared_segment { void *p; } zend_shared_segment; -typedef int (*create_segments_t)(size_t requested_size, zend_shared_segment ***shared_segments, int *shared_segment_count, char **error_in); +typedef int (*create_segments_t)(size_t requested_size, zend_shared_segment ***shared_segments, int *shared_segment_count, const char **error_in); typedef int (*detach_segment_t)(zend_shared_segment *shared_segment); typedef struct { From 0c83419057f2e917b2bb29078b0b2a38c69f34a3 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 21 Feb 2023 11:49:18 +0100 Subject: [PATCH 2/7] ext/opcache/ZendAccelerator: make `zps_failure_reason` const --- ext/opcache/ZendAccelerator.c | 6 +++--- ext/opcache/ZendAccelerator.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ext/opcache/ZendAccelerator.c b/ext/opcache/ZendAccelerator.c index fae2d9a2c9d3..f89c2502e382 100644 --- a/ext/opcache/ZendAccelerator.c +++ b/ext/opcache/ZendAccelerator.c @@ -112,8 +112,8 @@ zend_accel_shared_globals *accel_shared_globals = NULL; char accel_uname_id[32]; #endif bool accel_startup_ok = false; -static char *zps_failure_reason = NULL; -char *zps_api_failure_reason = NULL; +static const char *zps_failure_reason = NULL; +const char *zps_api_failure_reason = NULL; bool file_cache_only = false; /* process uses file cache only */ #if ENABLE_FILE_CACHE_FALLBACK bool fallback_process = false; /* process uses file cache fallback */ @@ -2809,7 +2809,7 @@ static int accelerator_remove_cb(zend_extension *element1, zend_extension *eleme return 0; } -static void zps_startup_failure(char *reason, char *api_reason, int (*cb)(zend_extension *, zend_extension *)) +static void zps_startup_failure(const char *reason, const char *api_reason, int (*cb)(zend_extension *, zend_extension *)) { accel_startup_ok = false; zps_failure_reason = reason; diff --git a/ext/opcache/ZendAccelerator.h b/ext/opcache/ZendAccelerator.h index 6270492613a2..568d8f497241 100644 --- a/ext/opcache/ZendAccelerator.h +++ b/ext/opcache/ZendAccelerator.h @@ -305,7 +305,7 @@ ZEND_TSRMLS_CACHE_EXTERN() extern zend_accel_globals accel_globals; #endif -extern char *zps_api_failure_reason; +extern const char *zps_api_failure_reason; BEGIN_EXTERN_C() From 61d15783275eaee6204bfc681bb9812807fcb915 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 21 Feb 2023 11:53:28 +0100 Subject: [PATCH 3/7] ext/opcache/zend_shared_alloc: make `model` const --- ext/opcache/zend_shared_alloc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/opcache/zend_shared_alloc.c b/ext/opcache/zend_shared_alloc.c index a374cf6f97de..c34a3df04d5c 100644 --- a/ext/opcache/zend_shared_alloc.c +++ b/ext/opcache/zend_shared_alloc.c @@ -169,7 +169,7 @@ int zend_shared_alloc_startup(size_t requested_size, size_t reserved_size) #endif if (ZCG(accel_directives).memory_model && ZCG(accel_directives).memory_model[0]) { - char *model = ZCG(accel_directives).memory_model; + const char *model = ZCG(accel_directives).memory_model; /* "cgi" is really "shm"... */ if (strncmp(ZCG(accel_directives).memory_model, "cgi", sizeof("cgi")) == 0) { model = "shm"; From 3ce7bbf1f2226b2c946f97c53912e1abd9cc14b0 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 21 Feb 2023 11:56:36 +0100 Subject: [PATCH 4/7] ext/date: make string pointers const --- ext/date/php_date.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/ext/date/php_date.c b/ext/date/php_date.c index cd06a8fb5458..f48d56194f1b 100644 --- a/ext/date/php_date.c +++ b/ext/date/php_date.c @@ -235,7 +235,7 @@ PHPAPI time_t php_time(void) #include "php_date_arginfo.h" -static char* guess_timezone(const timelib_tzdb *tzdb); +static const char* guess_timezone(const timelib_tzdb *tzdb); static void date_register_classes(void); /* }}} */ @@ -549,7 +549,7 @@ static PHP_INI_MH(OnUpdate_date_timezone) /* }}} */ /* {{{ Helper functions */ -static char* guess_timezone(const timelib_tzdb *tzdb) +static const char* guess_timezone(const timelib_tzdb *tzdb) { /* Checking whether timezone has been set with date_default_timezone_set() */ if (DATEG(timezone) && (strlen(DATEG(timezone))) > 0) { @@ -573,10 +573,9 @@ static char* guess_timezone(const timelib_tzdb *tzdb) PHPAPI timelib_tzinfo *get_timezone_info(void) { - char *tz; timelib_tzinfo *tzi; - tz = guess_timezone(DATE_TIMEZONEDB); + const char *tz = guess_timezone(DATE_TIMEZONEDB); tzi = php_date_parse_tzfile(tz, DATE_TIMEZONEDB); if (! tzi) { zend_throw_error(date_ce_date_error, "Timezone database is corrupt. Please file a bug report as this should never happen"); @@ -607,7 +606,7 @@ static const char * const day_short_names[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" }; -static char *english_suffix(timelib_sll number) +static const char *english_suffix(timelib_sll number) { if (number >= 10 && number <= 19) { return "th"; @@ -1667,7 +1666,7 @@ static const zend_object_iterator_funcs date_period_it_funcs = { NULL, /* get_gc */ }; -zend_object_iterator *date_object_period_get_iterator(zend_class_entry *ce, zval *object, int by_ref) /* {{{ */ +static zend_object_iterator *date_object_period_get_iterator(zend_class_entry *ce, zval *object, int by_ref) /* {{{ */ { date_period_it *iterator; @@ -2043,7 +2042,7 @@ static void php_timezone_to_string(php_timezone_obj *tzobj, zval *zv) } } -void date_timezone_object_to_hash(php_timezone_obj *tzobj, HashTable *props) +static void date_timezone_object_to_hash(php_timezone_obj *tzobj, HashTable *props) { zval zv; From b54c60f4efff3dd8ca68b9a602e43c23ee166239 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 21 Feb 2023 12:14:55 +0100 Subject: [PATCH 5/7] ext/dba: make string pointers const --- ext/dba/dba.c | 6 +++--- ext/dba/libcdb/cdb.c | 2 +- ext/dba/libcdb/cdb.h | 2 +- ext/dba/libcdb/cdb_make.c | 2 +- ext/dba/libcdb/cdb_make.h | 2 +- ext/dba/libflatfile/flatfile.c | 2 +- ext/dba/libflatfile/flatfile.h | 2 +- ext/dba/libinifile/inifile.c | 2 +- ext/dba/libinifile/inifile.h | 2 +- ext/dba/php_dba.h | 6 +++--- 10 files changed, 14 insertions(+), 14 deletions(-) diff --git a/ext/dba/dba.c b/ext/dba/dba.c index f468016c8ea9..b0af036e338c 100644 --- a/ext/dba/dba.c +++ b/ext/dba/dba.c @@ -462,10 +462,10 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, bool persistent) dba_mode_t modenr; dba_info *info, *other; const dba_handler *hptr; - char *error = NULL; + const char *error = NULL; int lock_mode, lock_flag = 0; - char *file_mode; - char *lock_file_mode = NULL; + const char *file_mode; + const char *lock_file_mode = NULL; int persistent_flag = persistent ? STREAM_OPEN_PERSISTENT : 0; zend_string *opened_path = NULL; char *lock_name; diff --git a/ext/dba/libcdb/cdb.c b/ext/dba/libcdb/cdb.c index 10cc4f985215..ac7769607ce9 100644 --- a/ext/dba/libcdb/cdb.c +++ b/ext/dba/libcdb/cdb.c @@ -185,7 +185,7 @@ int cdb_find(struct cdb *c, char *key, unsigned int len) /* }}} */ /* {{{ cdb_version */ -char *cdb_version() +const char *cdb_version() { return "0.75, $Id$"; } diff --git a/ext/dba/libcdb/cdb.h b/ext/dba/libcdb/cdb.h index 2225b2297cfa..4a94b81f832d 100644 --- a/ext/dba/libcdb/cdb.h +++ b/ext/dba/libcdb/cdb.h @@ -48,6 +48,6 @@ int cdb_find(struct cdb *, char *, unsigned int); #define cdb_datapos(c) ((c)->dpos) #define cdb_datalen(c) ((c)->dlen) -char *cdb_version(void); +const char *cdb_version(void); #endif diff --git a/ext/dba/libcdb/cdb_make.c b/ext/dba/libcdb/cdb_make.c index 8144ef10fb5d..c21b3c4d3ca7 100644 --- a/ext/dba/libcdb/cdb_make.c +++ b/ext/dba/libcdb/cdb_make.c @@ -236,7 +236,7 @@ int cdb_make_finish(struct cdb_make *c) /* }}} */ /* {{{ cdb_make_version */ -char *cdb_make_version() +const char *cdb_make_version() { return "0.75, $Id$"; } diff --git a/ext/dba/libcdb/cdb_make.h b/ext/dba/libcdb/cdb_make.h index 2410e3056225..96dbd43d1e56 100644 --- a/ext/dba/libcdb/cdb_make.h +++ b/ext/dba/libcdb/cdb_make.h @@ -55,6 +55,6 @@ int cdb_make_addbegin(struct cdb_make *, unsigned int, unsigned int); int cdb_make_addend(struct cdb_make *, unsigned int, unsigned int, uint32); int cdb_make_add(struct cdb_make *, char *, unsigned int, char *, unsigned int); int cdb_make_finish(struct cdb_make *); -char *cdb_make_version(void); +const char *cdb_make_version(void); #endif diff --git a/ext/dba/libflatfile/flatfile.c b/ext/dba/libflatfile/flatfile.c index a713373046dc..43d4f4712d97 100644 --- a/ext/dba/libflatfile/flatfile.c +++ b/ext/dba/libflatfile/flatfile.c @@ -276,7 +276,7 @@ datum flatfile_nextkey(flatfile *dba) { /* }}} */ /* {{{ flatfile_version */ -char *flatfile_version() +const char *flatfile_version() { return "1.0, $Id$"; } diff --git a/ext/dba/libflatfile/flatfile.h b/ext/dba/libflatfile/flatfile.h index bb39765151a5..801ec8054f4f 100644 --- a/ext/dba/libflatfile/flatfile.h +++ b/ext/dba/libflatfile/flatfile.h @@ -39,6 +39,6 @@ int flatfile_delete(flatfile *dba, datum key_datum); int flatfile_findkey(flatfile *dba, datum key_datum); datum flatfile_firstkey(flatfile *dba); datum flatfile_nextkey(flatfile *dba); -char *flatfile_version(void); +const char *flatfile_version(void); #endif diff --git a/ext/dba/libinifile/inifile.c b/ext/dba/libinifile/inifile.c index cdbd83769bd7..3d19f0a1222f 100644 --- a/ext/dba/libinifile/inifile.c +++ b/ext/dba/libinifile/inifile.c @@ -38,7 +38,7 @@ */ /* {{{ inifile_version */ -char *inifile_version() +const char *inifile_version() { return "1.0, $Id$"; } diff --git a/ext/dba/libinifile/inifile.h b/ext/dba/libinifile/inifile.h index 48e06be8a555..e931c70bcbf6 100644 --- a/ext/dba/libinifile/inifile.h +++ b/ext/dba/libinifile/inifile.h @@ -49,7 +49,7 @@ int inifile_delete_ex(inifile *dba, const key_type *key, bool *found); int inifile_replace(inifile *dba, const key_type *key, const val_type *val); int inifile_replace_ex(inifile *dba, const key_type *key, const val_type *val, bool *found); int inifile_append(inifile *dba, const key_type *key, const val_type *val); -char *inifile_version(void); +const char *inifile_version(void); key_type inifile_key_split(const char *group_name); char * inifile_key_string(const key_type *key); diff --git a/ext/dba/php_dba.h b/ext/dba/php_dba.h index edeed50a8449..d6a86f76b271 100644 --- a/ext/dba/php_dba.h +++ b/ext/dba/php_dba.h @@ -73,9 +73,9 @@ extern zend_module_entry dba_module_entry; #define dba_module_ptr &dba_module_entry typedef struct dba_handler { - char *name; /* handler name */ + const char *name; /* handler name */ int flags; /* whether and how dba does locking and other flags*/ - zend_result (*open)(dba_info *, char **error); + zend_result (*open)(dba_info *, const char **error); void (*close)(dba_info *); zend_string* (*fetch)(dba_info *, zend_string *, int); zend_result (*update)(dba_info *, zend_string *, zend_string *, int); @@ -92,7 +92,7 @@ typedef struct dba_handler { /* common prototypes which must be supplied by modules */ #define DBA_OPEN_FUNC(x) \ - zend_result dba_open_##x(dba_info *info, char **error) + zend_result dba_open_##x(dba_info *info, const char **error) #define DBA_CLOSE_FUNC(x) \ void dba_close_##x(dba_info *info) #define DBA_FETCH_FUNC(x) \ From e44ae592d1ae7f49043acfb063bcca5dd0fa8a98 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 21 Feb 2023 12:19:48 +0100 Subject: [PATCH 6/7] ext/sqlite3: make string pointers const --- ext/sqlite3/sqlite3.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ext/sqlite3/sqlite3.c b/ext/sqlite3/sqlite3.c index 721503e10ac9..2483899a7d10 100644 --- a/ext/sqlite3/sqlite3.c +++ b/ext/sqlite3/sqlite3.c @@ -1234,7 +1234,7 @@ PHP_METHOD(SQLite3, openBlob) { php_sqlite3_db_object *db_obj; zval *object = ZEND_THIS; - char *table, *column, *dbname = "main", *mode = "rb"; + const char *table, *column, *dbname = "main", *mode = "rb"; size_t table_len, column_len, dbname_len; zend_long rowid, flags = SQLITE_OPEN_READONLY, sqlite_flags = 0; sqlite3_blob *blob = NULL; @@ -1338,7 +1338,7 @@ PHP_METHOD(SQLite3, backup) { php_sqlite3_db_object *source_obj; php_sqlite3_db_object *destination_obj; - char *source_dbname = "main", *destination_dbname = "main"; + const char *source_dbname = "main", *destination_dbname = "main"; size_t source_dbname_length, destination_dbname_length; zval *source_zval = ZEND_THIS; zval *destination_zval; From 685ceaf8f2f0c692ec649d308806719b54d2a9de Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 21 Feb 2023 12:21:14 +0100 Subject: [PATCH 7/7] ext/curl: make string pointers const --- ext/curl/curl_file.c | 4 ++-- ext/curl/interface.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ext/curl/curl_file.c b/ext/curl/curl_file.c index fdb6ea359607..fd8baecc6838 100644 --- a/ext/curl/curl_file.c +++ b/ext/curl/curl_file.c @@ -65,7 +65,7 @@ PHP_FUNCTION(curl_file_create) } /* }}} */ -static void curlfile_get_property(char *name, size_t name_len, INTERNAL_FUNCTION_PARAMETERS) +static void curlfile_get_property(const char *name, size_t name_len, INTERNAL_FUNCTION_PARAMETERS) { zval *res, rv; @@ -74,7 +74,7 @@ static void curlfile_get_property(char *name, size_t name_len, INTERNAL_FUNCTION RETURN_COPY_DEREF(res); } -static void curlfile_set_property(char *name, size_t name_len, INTERNAL_FUNCTION_PARAMETERS) +static void curlfile_set_property(const char *name, size_t name_len, INTERNAL_FUNCTION_PARAMETERS) { zend_string *arg; diff --git a/ext/curl/interface.c b/ext/curl/interface.c index fe80518f3d06..34202c1e9685 100644 --- a/ext/curl/interface.c +++ b/ext/curl/interface.c @@ -2073,7 +2073,7 @@ static zend_result _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue struct curl_slist *slist = NULL; if (Z_TYPE_P(zvalue) != IS_ARRAY) { - char *name = NULL; + const char *name = NULL; switch (option) { case CURLOPT_HTTPHEADER: name = "CURLOPT_HTTPHEADER";