Skip to content

Commit 1675d32

Browse files
authored
Fix printf style issues in Windows specific code (GH-17452)
A couple of calls pass strings as formats (`-Wformat-security`), and some others mix up types (`-Wformat`).
1 parent 26bf239 commit 1675d32

File tree

10 files changed

+17
-17
lines changed

10 files changed

+17
-17
lines changed

Zend/zend_extensions.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ zend_result zend_load_extension(const char *path)
4545
#ifdef ZEND_WIN32
4646
char *err;
4747
if (!php_win32_image_compatible(handle, &err)) {
48-
zend_error(E_CORE_WARNING, err);
48+
zend_error(E_CORE_WARNING, "%s", err);
4949
return FAILURE;
5050
}
5151
#endif

ext/opcache/jit/zend_jit.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3460,7 +3460,7 @@ void zend_jit_unprotect(void)
34603460
if (!VirtualProtect(dasm_buf, dasm_size, new, &old)) {
34613461
DWORD err = GetLastError();
34623462
char *msg = php_win32_error_to_msg(err);
3463-
fprintf(stderr, "VirtualProtect() failed [%u] %s\n", err, msg);
3463+
fprintf(stderr, "VirtualProtect() failed [%lu] %s\n", err, msg);
34643464
php_win32_error_msg_free(msg);
34653465
}
34663466
}
@@ -3487,7 +3487,7 @@ void zend_jit_protect(void)
34873487
if (!VirtualProtect(dasm_buf, dasm_size, PAGE_EXECUTE_READ, &old)) {
34883488
DWORD err = GetLastError();
34893489
char *msg = php_win32_error_to_msg(err);
3490-
fprintf(stderr, "VirtualProtect() failed [%u] %s\n", err, msg);
3490+
fprintf(stderr, "VirtualProtect() failed [%lu] %s\n", err, msg);
34913491
php_win32_error_msg_free(msg);
34923492
}
34933493
}
@@ -3731,7 +3731,7 @@ void zend_jit_startup(void *buf, size_t size, bool reattached)
37313731
if (!VirtualProtect(dasm_buf, dasm_size, PAGE_EXECUTE_READWRITE, &old)) {
37323732
DWORD err = GetLastError();
37333733
char *msg = php_win32_error_to_msg(err);
3734-
fprintf(stderr, "VirtualProtect() failed [%u] %s\n", err, msg);
3734+
fprintf(stderr, "VirtualProtect() failed [%lu] %s\n", err, msg);
37353735
php_win32_error_msg_free(msg);
37363736
}
37373737
} else {
@@ -3740,7 +3740,7 @@ void zend_jit_startup(void *buf, size_t size, bool reattached)
37403740
if (!VirtualProtect(dasm_buf, dasm_size, PAGE_EXECUTE_READ, &old)) {
37413741
DWORD err = GetLastError();
37423742
char *msg = php_win32_error_to_msg(err);
3743-
fprintf(stderr, "VirtualProtect() failed [%u] %s\n", err, msg);
3743+
fprintf(stderr, "VirtualProtect() failed [%lu] %s\n", err, msg);
37443744
php_win32_error_msg_free(msg);
37453745
}
37463746
}

ext/opcache/shared_alloc_win32.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ void zend_shared_alloc_create_lock(void)
9090
{
9191
memory_mutex = CreateMutex(NULL, FALSE, create_name_with_username(ACCEL_MUTEX_NAME));
9292
if (!memory_mutex) {
93-
zend_accel_error(ACCEL_LOG_FATAL, "Cannot create mutex (error %u)", GetLastError());
93+
zend_accel_error(ACCEL_LOG_FATAL, "Cannot create mutex (error %lu)", GetLastError());
9494
return;
9595
}
9696
ReleaseMutex(memory_mutex);

ext/standard/dl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ PHPAPI int php_load_extension(const char *filename, int type, int start_now)
177177

178178
#ifdef PHP_WIN32
179179
if (!php_win32_image_compatible(handle, &err1)) {
180-
php_error_docref(NULL, error_type, err1);
180+
php_error_docref(NULL, error_type, "%s", err1);
181181
efree(err1);
182182
DL_UNLOAD(handle);
183183
return FAILURE;

ext/standard/info.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@ static void php_get_windows_cpu(char *buf, size_t bufsize)
609609
GetSystemInfo(&SysInfo);
610610
switch (SysInfo.wProcessorArchitecture) {
611611
case PROCESSOR_ARCHITECTURE_INTEL :
612-
snprintf(buf, bufsize, "i%d", SysInfo.dwProcessorType);
612+
snprintf(buf, bufsize, "i%lu", SysInfo.dwProcessorType);
613613
break;
614614
case PROCESSOR_ARCHITECTURE_MIPS :
615615
snprintf(buf, bufsize, "MIPS R%d000", SysInfo.wProcessorLevel);
@@ -671,7 +671,7 @@ PHPAPI zend_string *php_get_uname(char mode)
671671
if (mode == 's') {
672672
php_uname = "Windows NT";
673673
} else if (mode == 'r') {
674-
return strpprintf(0, "%d.%d", dwWindowsMajorVersion, dwWindowsMinorVersion);
674+
return strpprintf(0, "%lu.%lu", dwWindowsMajorVersion, dwWindowsMinorVersion);
675675
} else if (mode == 'n') {
676676
php_uname = ComputerName;
677677
} else if (mode == 'v') {
@@ -680,7 +680,7 @@ PHPAPI zend_string *php_get_uname(char mode)
680680

681681
ZEND_ASSERT(winver != NULL);
682682

683-
zend_string *build_with_version = strpprintf(0, "build %d (%s)", dwBuild, winver);
683+
zend_string *build_with_version = strpprintf(0, "build %lu (%s)", dwBuild, winver);
684684
efree(winver);
685685
return build_with_version;
686686
} else if (mode == 'm') {
@@ -702,7 +702,7 @@ PHPAPI zend_string *php_get_uname(char mode)
702702
}
703703
}
704704

705-
zend_string *build_with_all_info = strpprintf(0, "%s %s %d.%d build %d (%s) %s",
705+
zend_string *build_with_all_info = strpprintf(0, "%s %s %lu.%lu build %lu (%s) %s",
706706
"Windows NT", ComputerName, dwWindowsMajorVersion, dwWindowsMinorVersion, dwBuild,
707707
winver ? winver: "unknown", wincpu);
708708
efree(winver);

ext/standard/link.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ PHP_FUNCTION(readlink)
7373

7474
if (ret == -1) {
7575
#ifdef PHP_WIN32
76-
php_error_docref(NULL, E_WARNING, "readlink failed to read the symbolic link (%s), error %d", link, GetLastError());
76+
php_error_docref(NULL, E_WARNING, "readlink failed to read the symbolic link (%s), error %ld", link, GetLastError());
7777
#else
7878
php_error_docref(NULL, E_WARNING, "%s", strerror(errno));
7979
#endif

main/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2191,7 +2191,7 @@ zend_result php_module_startup(sapi_module_struct *sf, zend_module_entry *additi
21912191
#ifdef PHP_WIN32
21922192
char *img_err;
21932193
if (!php_win32_crt_compatible(&img_err)) {
2194-
php_error(E_CORE_WARNING, img_err);
2194+
php_error(E_CORE_WARNING, "%s", img_err);
21952195
efree(img_err);
21962196
return FAILURE;
21972197
}

main/php_ini.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ static void php_load_zend_extension_cb(void *arg)
378378

379379
#ifdef PHP_WIN32
380380
if (!php_win32_image_compatible(handle, &err1)) {
381-
php_error(E_CORE_WARNING, err1);
381+
php_error(E_CORE_WARNING, "%s", err1);
382382
efree(err1);
383383
efree(libpath);
384384
DL_UNLOAD(handle);

win32/codepage.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,7 @@ PHP_FUNCTION(sapi_windows_cp_set)
610610
cp = php_win32_cp_set_by_id((DWORD)id);
611611
}
612612
if (!cp) {
613-
php_error_docref(NULL, E_WARNING, "Failed to switch to codepage %d", id);
613+
php_error_docref(NULL, E_WARNING, "Failed to switch to codepage " ZEND_LONG_FMT, id);
614614
RETURN_FALSE;
615615
}
616616

win32/winutil.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ static zend_always_inline BOOL is_compatible(HMODULE handle, BOOL is_smaller, ch
468468
if (GetModuleFileName(handle, buf, sizeof(buf)) != 0) {
469469
spprintf(err, 0, format, buf, major, minor, PHP_LINKER_MAJOR, PHP_LINKER_MINOR);
470470
} else {
471-
spprintf(err, 0, "Can't retrieve the module name (error %u)", GetLastError());
471+
spprintf(err, 0, "Can't retrieve the module name (error %lu)", GetLastError());
472472
}
473473
return FALSE;
474474
}
@@ -493,7 +493,7 @@ PHP_WINUTIL_API BOOL php_win32_crt_compatible(char **err)
493493
# endif
494494
HMODULE handle = GetModuleHandle(crt_name);
495495
if (handle == NULL) {
496-
spprintf(err, 0, "Can't get handle of module %s (error %u)", crt_name, GetLastError());
496+
spprintf(err, 0, "Can't get handle of module %s (error %lu)", crt_name, GetLastError());
497497
return FALSE;
498498
}
499499
return is_compatible(handle, FALSE, "'%s' %u.%u is not compatible with this PHP build linked with %d.%d", err);

0 commit comments

Comments
 (0)