Skip to content

Fix printf style issues in Windows specific code #17452

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

Merged
merged 1 commit into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Zend/zend_extensions.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ zend_result zend_load_extension(const char *path)
#ifdef ZEND_WIN32
char *err;
if (!php_win32_image_compatible(handle, &err)) {
zend_error(E_CORE_WARNING, err);
zend_error(E_CORE_WARNING, "%s", err);
return FAILURE;
}
#endif
Expand Down
8 changes: 4 additions & 4 deletions ext/opcache/jit/zend_jit.c
Original file line number Diff line number Diff line change
Expand Up @@ -3460,7 +3460,7 @@ void zend_jit_unprotect(void)
if (!VirtualProtect(dasm_buf, dasm_size, new, &old)) {
DWORD err = GetLastError();
char *msg = php_win32_error_to_msg(err);
fprintf(stderr, "VirtualProtect() failed [%u] %s\n", err, msg);
fprintf(stderr, "VirtualProtect() failed [%lu] %s\n", err, msg);
php_win32_error_msg_free(msg);
}
}
Expand All @@ -3487,7 +3487,7 @@ void zend_jit_protect(void)
if (!VirtualProtect(dasm_buf, dasm_size, PAGE_EXECUTE_READ, &old)) {
DWORD err = GetLastError();
char *msg = php_win32_error_to_msg(err);
fprintf(stderr, "VirtualProtect() failed [%u] %s\n", err, msg);
fprintf(stderr, "VirtualProtect() failed [%lu] %s\n", err, msg);
php_win32_error_msg_free(msg);
}
}
Expand Down Expand Up @@ -3731,7 +3731,7 @@ void zend_jit_startup(void *buf, size_t size, bool reattached)
if (!VirtualProtect(dasm_buf, dasm_size, PAGE_EXECUTE_READWRITE, &old)) {
DWORD err = GetLastError();
char *msg = php_win32_error_to_msg(err);
fprintf(stderr, "VirtualProtect() failed [%u] %s\n", err, msg);
fprintf(stderr, "VirtualProtect() failed [%lu] %s\n", err, msg);
php_win32_error_msg_free(msg);
}
} else {
Expand All @@ -3740,7 +3740,7 @@ void zend_jit_startup(void *buf, size_t size, bool reattached)
if (!VirtualProtect(dasm_buf, dasm_size, PAGE_EXECUTE_READ, &old)) {
DWORD err = GetLastError();
char *msg = php_win32_error_to_msg(err);
fprintf(stderr, "VirtualProtect() failed [%u] %s\n", err, msg);
fprintf(stderr, "VirtualProtect() failed [%lu] %s\n", err, msg);
php_win32_error_msg_free(msg);
}
}
Expand Down
2 changes: 1 addition & 1 deletion ext/opcache/shared_alloc_win32.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ void zend_shared_alloc_create_lock(void)
{
memory_mutex = CreateMutex(NULL, FALSE, create_name_with_username(ACCEL_MUTEX_NAME));
if (!memory_mutex) {
zend_accel_error(ACCEL_LOG_FATAL, "Cannot create mutex (error %u)", GetLastError());
zend_accel_error(ACCEL_LOG_FATAL, "Cannot create mutex (error %lu)", GetLastError());
return;
}
ReleaseMutex(memory_mutex);
Expand Down
2 changes: 1 addition & 1 deletion ext/standard/dl.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ PHPAPI int php_load_extension(const char *filename, int type, int start_now)

#ifdef PHP_WIN32
if (!php_win32_image_compatible(handle, &err1)) {
php_error_docref(NULL, error_type, err1);
php_error_docref(NULL, error_type, "%s", err1);
efree(err1);
DL_UNLOAD(handle);
return FAILURE;
Expand Down
8 changes: 4 additions & 4 deletions ext/standard/info.c
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ static void php_get_windows_cpu(char *buf, size_t bufsize)
GetSystemInfo(&SysInfo);
switch (SysInfo.wProcessorArchitecture) {
case PROCESSOR_ARCHITECTURE_INTEL :
snprintf(buf, bufsize, "i%d", SysInfo.dwProcessorType);
snprintf(buf, bufsize, "i%lu", SysInfo.dwProcessorType);
break;
case PROCESSOR_ARCHITECTURE_MIPS :
snprintf(buf, bufsize, "MIPS R%d000", SysInfo.wProcessorLevel);
Expand Down Expand Up @@ -671,7 +671,7 @@ PHPAPI zend_string *php_get_uname(char mode)
if (mode == 's') {
php_uname = "Windows NT";
} else if (mode == 'r') {
return strpprintf(0, "%d.%d", dwWindowsMajorVersion, dwWindowsMinorVersion);
return strpprintf(0, "%lu.%lu", dwWindowsMajorVersion, dwWindowsMinorVersion);
} else if (mode == 'n') {
php_uname = ComputerName;
} else if (mode == 'v') {
Expand All @@ -680,7 +680,7 @@ PHPAPI zend_string *php_get_uname(char mode)

ZEND_ASSERT(winver != NULL);

zend_string *build_with_version = strpprintf(0, "build %d (%s)", dwBuild, winver);
zend_string *build_with_version = strpprintf(0, "build %lu (%s)", dwBuild, winver);
efree(winver);
return build_with_version;
} else if (mode == 'm') {
Expand All @@ -702,7 +702,7 @@ PHPAPI zend_string *php_get_uname(char mode)
}
}

zend_string *build_with_all_info = strpprintf(0, "%s %s %d.%d build %d (%s) %s",
zend_string *build_with_all_info = strpprintf(0, "%s %s %lu.%lu build %lu (%s) %s",
"Windows NT", ComputerName, dwWindowsMajorVersion, dwWindowsMinorVersion, dwBuild,
winver ? winver: "unknown", wincpu);
efree(winver);
Expand Down
2 changes: 1 addition & 1 deletion ext/standard/link.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ PHP_FUNCTION(readlink)

if (ret == -1) {
#ifdef PHP_WIN32
php_error_docref(NULL, E_WARNING, "readlink failed to read the symbolic link (%s), error %d", link, GetLastError());
php_error_docref(NULL, E_WARNING, "readlink failed to read the symbolic link (%s), error %ld", link, GetLastError());
#else
php_error_docref(NULL, E_WARNING, "%s", strerror(errno));
#endif
Expand Down
2 changes: 1 addition & 1 deletion main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2191,7 +2191,7 @@ zend_result php_module_startup(sapi_module_struct *sf, zend_module_entry *additi
#ifdef PHP_WIN32
char *img_err;
if (!php_win32_crt_compatible(&img_err)) {
php_error(E_CORE_WARNING, img_err);
php_error(E_CORE_WARNING, "%s", img_err);
efree(img_err);
return FAILURE;
}
Expand Down
2 changes: 1 addition & 1 deletion main/php_ini.c
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ static void php_load_zend_extension_cb(void *arg)

#ifdef PHP_WIN32
if (!php_win32_image_compatible(handle, &err1)) {
php_error(E_CORE_WARNING, err1);
php_error(E_CORE_WARNING, "%s", err1);
efree(err1);
efree(libpath);
DL_UNLOAD(handle);
Expand Down
2 changes: 1 addition & 1 deletion win32/codepage.c
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ PHP_FUNCTION(sapi_windows_cp_set)
cp = php_win32_cp_set_by_id((DWORD)id);
}
if (!cp) {
php_error_docref(NULL, E_WARNING, "Failed to switch to codepage %d", id);
php_error_docref(NULL, E_WARNING, "Failed to switch to codepage " ZEND_LONG_FMT, id);
RETURN_FALSE;
}

Expand Down
4 changes: 2 additions & 2 deletions win32/winutil.c
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ static zend_always_inline BOOL is_compatible(HMODULE handle, BOOL is_smaller, ch
if (GetModuleFileName(handle, buf, sizeof(buf)) != 0) {
spprintf(err, 0, format, buf, major, minor, PHP_LINKER_MAJOR, PHP_LINKER_MINOR);
} else {
spprintf(err, 0, "Can't retrieve the module name (error %u)", GetLastError());
spprintf(err, 0, "Can't retrieve the module name (error %lu)", GetLastError());
}
return FALSE;
}
Expand All @@ -493,7 +493,7 @@ PHP_WINUTIL_API BOOL php_win32_crt_compatible(char **err)
# endif
HMODULE handle = GetModuleHandle(crt_name);
if (handle == NULL) {
spprintf(err, 0, "Can't get handle of module %s (error %u)", crt_name, GetLastError());
spprintf(err, 0, "Can't get handle of module %s (error %lu)", crt_name, GetLastError());
return FALSE;
}
return is_compatible(handle, FALSE, "'%s' %u.%u is not compatible with this PHP build linked with %d.%d", err);
Expand Down
Loading