From 7d5691cd69c4528e2bc0bb909c60310cbf03b33a Mon Sep 17 00:00:00 2001 From: Sebastian Ramadan Date: Tue, 21 Nov 2017 22:50:27 +0100 Subject: [PATCH] Fix some printf() specifier usages Use PRIu32 when printing uint32_t. Fix some %u/%d confusions. Add some casts where types are not standardized. --- main/main.c | 20 ++++++++++---------- sapi/fpm/fpm/fpm_status.c | 30 +++++++++++++++--------------- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/main/main.c b/main/main.c index 3e7f956e24..d080439988 100644 --- a/main/main.c +++ b/main/main.c @@ -1162,14 +1162,14 @@ static ZEND_COLD void php_error_cb(int type, const char *error_filename, const u syslog(LOG_ALERT, "PHP %s: %s (%s)", error_type_str, buffer, GetCommandLine()); } #endif - spprintf(&log_buffer, 0, "PHP %s: %s in %s on line %d", error_type_str, buffer, error_filename, error_lineno); + spprintf(&log_buffer, 0, "PHP %s: %s in %s on line %" PRIu32, error_type_str, buffer, error_filename, error_lineno); php_log_err_with_severity(log_buffer, syslog_type_int); efree(log_buffer); } if (PG(display_errors) && ((module_initialized && !PG(during_request_startup)) || (PG(display_startup_errors)))) { if (PG(xmlrpc_errors)) { - php_printf("faultCode" ZEND_LONG_FMT "faultString%s:%s in %s on line %d", PG(xmlrpc_error_number), error_type_str, buffer, error_filename, error_lineno); + php_printf("faultCode" ZEND_LONG_FMT "faultString%s:%s in %s on line %" PRIu32 "", PG(xmlrpc_error_number), error_type_str, buffer, error_filename, error_lineno); } else { char *prepend_string = INI_STR("error_prepend_string"); char *append_string = INI_STR("error_append_string"); @@ -1177,22 +1177,22 @@ static ZEND_COLD void php_error_cb(int type, const char *error_filename, const u if (PG(html_errors)) { if (type == E_ERROR || type == E_PARSE) { zend_string *buf = php_escape_html_entities((unsigned char*)buffer, buffer_len, 0, ENT_COMPAT, get_safe_charset_hint()); - php_printf("%s
\n%s: %s in %s on line %d
\n%s", STR_PRINT(prepend_string), error_type_str, ZSTR_VAL(buf), error_filename, error_lineno, STR_PRINT(append_string)); + php_printf("%s
\n%s: %s in %s on line %" PRIu32 "
\n%s", STR_PRINT(prepend_string), error_type_str, ZSTR_VAL(buf), error_filename, error_lineno, STR_PRINT(append_string)); zend_string_free(buf); } else { - php_printf("%s
\n%s: %s in %s on line %d
\n%s", STR_PRINT(prepend_string), error_type_str, buffer, error_filename, error_lineno, STR_PRINT(append_string)); + php_printf("%s
\n%s: %s in %s on line %" PRIu32 "
\n%s", STR_PRINT(prepend_string), error_type_str, buffer, error_filename, error_lineno, STR_PRINT(append_string)); } } else { /* Write CLI/CGI errors to stderr if display_errors = "stderr" */ if ((!strcmp(sapi_module.name, "cli") || !strcmp(sapi_module.name, "cgi")) && PG(display_errors) == PHP_DISPLAY_ERRORS_STDERR ) { - fprintf(stderr, "%s: %s in %s on line %u\n", error_type_str, buffer, error_filename, error_lineno); + fprintf(stderr, "%s: %s in %s on line %" PRIu32 "\n", error_type_str, buffer, error_filename, error_lineno); #ifdef PHP_WIN32 fflush(stderr); #endif } else { - php_printf("%s\n%s: %s in %s on line %d\n%s", STR_PRINT(prepend_string), error_type_str, buffer, error_filename, error_lineno, STR_PRINT(append_string)); + php_printf("%s\n%s: %s in %s on line %" PRIu32 "\n%s", STR_PRINT(prepend_string), error_type_str, buffer, error_filename, error_lineno, STR_PRINT(append_string)); } } } @@ -1212,7 +1212,7 @@ static ZEND_COLD void php_error_cb(int type, const char *error_filename, const u trigger_break=0; break; } - zend_output_debug_string(trigger_break, "%s(%d) : %s - %s", error_filename, error_lineno, error_type_str, buffer); + zend_output_debug_string(trigger_break, "%s(%" PRIu32 ") : %s - %s", error_filename, error_lineno, error_type_str, buffer); } #endif } @@ -1509,17 +1509,17 @@ static ZEND_COLD void php_message_handler_for_zend(zend_long message, const void if (message==ZMSG_MEMORY_LEAK_DETECTED) { zend_leak_info *t = (zend_leak_info *) data; - snprintf(memory_leak_buf, 512, "%s(%d) : Freeing " ZEND_ADDR_FMT " (%zu bytes), script=%s\n", t->filename, t->lineno, (size_t)t->addr, t->size, SAFE_FILENAME(SG(request_info).path_translated)); + snprintf(memory_leak_buf, 512, "%s(%" PRIu32 ") : Freeing " ZEND_ADDR_FMT " (%zu bytes), script=%s\n", t->filename, t->lineno, (size_t)t->addr, t->size, SAFE_FILENAME(SG(request_info).path_translated)); if (t->orig_filename) { char relay_buf[512]; - snprintf(relay_buf, 512, "%s(%d) : Actual location (location was relayed)\n", t->orig_filename, t->orig_lineno); + snprintf(relay_buf, 512, "%s(%" PRIu32 ") : Actual location (location was relayed)\n", t->orig_filename, t->orig_lineno); strlcat(memory_leak_buf, relay_buf, sizeof(memory_leak_buf)); } } else { unsigned long leak_count = (zend_uintptr_t) data; - snprintf(memory_leak_buf, 512, "Last leak repeated %ld time%s\n", leak_count, (leak_count>1?"s":"")); + snprintf(memory_leak_buf, 512, "Last leak repeated %lu time%s\n", leak_count, (leak_count>1?"s":"")); } # if defined(PHP_WIN32) OutputDebugString(memory_leak_buf); diff --git a/sapi/fpm/fpm/fpm_status.c b/sapi/fpm/fpm/fpm_status.c index 42d7d7bae0..92b55ab457 100644 --- a/sapi/fpm/fpm/fpm_status.c +++ b/sapi/fpm/fpm/fpm_status.c @@ -151,9 +151,9 @@ int fpm_status_handle_request(void) /* {{{ */ "start since%lu\n" "accepted conn%lu\n" #ifdef HAVE_FPM_LQ - "listen queue%u\n" - "max listen queue%u\n" - "listen queue len%d\n" + "listen queue%d\n" + "max listen queue%d\n" + "listen queue len%u\n" #endif "idle processes%d\n" "active processes%d\n" @@ -223,9 +223,9 @@ int fpm_status_handle_request(void) /* {{{ */ "%lu\n" "%lu\n" #ifdef HAVE_FPM_LQ - "%u\n" - "%u\n" - "%d\n" + "%d\n" + "%d\n" + "%u\n" #endif "%d\n" "%d\n" @@ -273,9 +273,9 @@ int fpm_status_handle_request(void) /* {{{ */ "\"start since\":%lu," "\"accepted conn\":%lu," #ifdef HAVE_FPM_LQ - "\"listen queue\":%u," - "\"max listen queue\":%u," - "\"listen queue len\":%d," + "\"listen queue\":%d," + "\"max listen queue\":%d," + "\"listen queue len\":%u," #endif "\"idle processes\":%d," "\"active processes\":%d," @@ -323,9 +323,9 @@ int fpm_status_handle_request(void) /* {{{ */ "start since: %lu\n" "accepted conn: %lu\n" #ifdef HAVE_FPM_LQ - "listen queue: %u\n" - "max listen queue: %u\n" - "listen queue len: %d\n" + "listen queue: %d\n" + "max listen queue: %d\n" + "listen queue len: %u\n" #endif "idle processes: %d\n" "active processes: %d\n" @@ -362,7 +362,7 @@ int fpm_status_handle_request(void) /* {{{ */ scoreboard.pool, PM2STR(scoreboard.pm), time_buffer, - now_epoch - scoreboard.start_epoch, + (unsigned long) (now_epoch - scoreboard.start_epoch), scoreboard.requests, #ifdef HAVE_FPM_LQ scoreboard.lq, @@ -443,10 +443,10 @@ int fpm_status_handle_request(void) /* {{{ */ } strftime(time_buffer, sizeof(time_buffer) - 1, time_format, localtime(&proc.start_epoch)); spprintf(&buffer, 0, full_syntax, - proc.pid, + (int) proc.pid, fpm_request_get_stage_name(proc.request_stage), time_buffer, - now_epoch - proc.start_epoch, + (unsigned long) (now_epoch - proc.start_epoch), proc.requests, duration.tv_sec * 1000000UL + duration.tv_usec, proc.request_method[0] != '\0' ? proc.request_method : "-", -- 2.50.1