diff --git a/ext/pdo_pgsql/pgsql_statement.c b/ext/pdo_pgsql/pgsql_statement.c index 3485bd8df0024..f9320fd86ea83 100644 --- a/ext/pdo_pgsql/pgsql_statement.c +++ b/ext/pdo_pgsql/pgsql_statement.c @@ -526,10 +526,10 @@ static int pgsql_stmt_fetch(pdo_stmt_t *stmt, ExecStatusType status; switch (ori) { - case PDO_FETCH_ORI_NEXT: spprintf(&ori_str, 0, "NEXT"); break; - case PDO_FETCH_ORI_PRIOR: spprintf(&ori_str, 0, "BACKWARD"); break; - case PDO_FETCH_ORI_FIRST: spprintf(&ori_str, 0, "FIRST"); break; - case PDO_FETCH_ORI_LAST: spprintf(&ori_str, 0, "LAST"); break; + case PDO_FETCH_ORI_NEXT: ori_str = "NEXT"; break; + case PDO_FETCH_ORI_PRIOR: ori_str = "BACKWARD"; break; + case PDO_FETCH_ORI_FIRST: ori_str = "FIRST"; break; + case PDO_FETCH_ORI_LAST: ori_str = "LAST"; break; case PDO_FETCH_ORI_ABS: spprintf(&ori_str, 0, "ABSOLUTE " ZEND_LONG_FMT, offset); break; case PDO_FETCH_ORI_REL: spprintf(&ori_str, 0, "RELATIVE " ZEND_LONG_FMT, offset); break; default: @@ -542,7 +542,9 @@ static int pgsql_stmt_fetch(pdo_stmt_t *stmt, } spprintf(&q, 0, "FETCH %s FROM %s", ori_str, S->cursor_name); - efree(ori_str); + if (ori == PDO_FETCH_ORI_ABS || ori == PDO_FETCH_ORI_REL) { + efree(ori_str); + } S->result = PQexec(S->H->server, q); efree(q); status = PQresultStatus(S->result); diff --git a/ext/standard/http_fopen_wrapper.c b/ext/standard/http_fopen_wrapper.c index 9fefe153622fc..85f5974be7e57 100644 --- a/ext/standard/http_fopen_wrapper.c +++ b/ext/standard/http_fopen_wrapper.c @@ -638,13 +638,9 @@ static php_stream *php_stream_url_wrap_http_ex(php_stream_wrapper *wrapper, /* protocol version we are speaking */ if (context && (tmpzval = php_stream_context_get_option(context, "http", "protocol_version")) != NULL) { - char *protocol_version; - spprintf(&protocol_version, 0, "%.1F", zval_get_double(tmpzval)); - smart_str_appends(&req_buf, " HTTP/"); - smart_str_appends(&req_buf, protocol_version); + smart_str_append_printf(&req_buf, "%.1F", zval_get_double(tmpzval)); smart_str_appends(&req_buf, "\r\n"); - efree(protocol_version); } else { smart_str_appends(&req_buf, " HTTP/1.1\r\n"); } diff --git a/ext/sysvmsg/sysvmsg.c b/ext/sysvmsg/sysvmsg.c index d906aa2315e4d..456a6f51735e0 100644 --- a/ext/sysvmsg/sysvmsg.c +++ b/ext/sysvmsg/sysvmsg.c @@ -383,10 +383,12 @@ PHP_FUNCTION(msg_send) message_len = spprintf(&p, 0, ZEND_LONG_FMT, Z_LVAL_P(message)); break; case IS_FALSE: - message_len = spprintf(&p, 0, "0"); + p = "0"; + message_len = 1; break; case IS_TRUE: - message_len = spprintf(&p, 0, "1"); + p = "1"; + message_len = 1; break; case IS_DOUBLE: message_len = spprintf(&p, 0, "%F", Z_DVAL_P(message)); @@ -400,7 +402,7 @@ PHP_FUNCTION(msg_send) messagebuffer = safe_emalloc(message_len, 1, sizeof(struct php_msgbuf)); memcpy(messagebuffer->mtext, p, message_len + 1); - if (Z_TYPE_P(message) != IS_STRING) { + if (Z_TYPE_P(message) == IS_LONG || Z_TYPE_P(message) == IS_DOUBLE) { efree(p); } } diff --git a/main/main.c b/main/main.c index 1cff1cee27a40..be03d9a70fda6 100644 --- a/main/main.c +++ b/main/main.c @@ -1049,7 +1049,7 @@ PHPAPI ZEND_COLD void php_verror(const char *docref, const char *params, int typ const char *space = ""; const char *class_name = ""; const char *function; - int origin_len; + size_t origin_len; char *origin; zend_string *message; int is_function = 0; @@ -1116,9 +1116,10 @@ PHPAPI ZEND_COLD void php_verror(const char *docref, const char *params, int typ /* if we still have memory then format the origin */ if (is_function) { - origin_len = (int)spprintf(&origin, 0, "%s%s%s(%s)", class_name, space, function, params); + origin_len = spprintf(&origin, 0, "%s%s%s(%s)", class_name, space, function, params); } else { - origin_len = (int)spprintf(&origin, 0, "%s", function); + origin_len = strlen(function); + origin = estrndup(function, origin_len); } if (PG(html_errors)) { @@ -1135,14 +1136,14 @@ PHPAPI ZEND_COLD void php_verror(const char *docref, const char *params, int typ /* no docref given but function is known (the default) */ if (!docref && is_function) { - int doclen; + size_t doclen; while (*function == '_') { function++; } if (space[0] == '\0') { - doclen = (int)spprintf(&docref_buf, 0, "function.%s", function); + doclen = spprintf(&docref_buf, 0, "function.%s", function); } else { - doclen = (int)spprintf(&docref_buf, 0, "%s.%s", class_name, function); + doclen = spprintf(&docref_buf, 0, "%s.%s", class_name, function); } while((p = strchr(docref_buf, '_')) != NULL) { *p = '-'; diff --git a/sapi/fpm/fpm/fpm_conf.c b/sapi/fpm/fpm/fpm_conf.c index e18cfebda08f5..7743d28f448dd 100644 --- a/sapi/fpm/fpm/fpm_conf.c +++ b/sapi/fpm/fpm/fpm_conf.c @@ -1383,14 +1383,14 @@ static void fpm_conf_cleanup(int which, void *arg) /* {{{ */ static void fpm_conf_ini_parser_include(char *inc, void *arg) /* {{{ */ { - char *filename; int *error = (int *)arg; php_glob_t g; size_t i; if (!inc || !arg) return; if (*error) return; /* We got already an error. Switch to the end. */ - spprintf(&filename, 0, "%s", ini_filename); + + const char *filename = ini_filename; { g.gl_offs = 0; @@ -1398,31 +1398,26 @@ static void fpm_conf_ini_parser_include(char *inc, void *arg) /* {{{ */ #ifdef PHP_GLOB_NOMATCH if (i == PHP_GLOB_NOMATCH) { zlog(ZLOG_WARNING, "Nothing matches the include pattern '%s' from %s at line %d.", inc, filename, ini_lineno); - efree(filename); return; } #endif /* PHP_GLOB_NOMATCH */ zlog(ZLOG_ERROR, "Unable to globalize '%s' (ret=%zd) from %s at line %d.", inc, i, filename, ini_lineno); *error = 1; - efree(filename); return; } for (i = 0; i < g.gl_pathc; i++) { - int len = strlen(g.gl_pathv[i]); + size_t len = strlen(g.gl_pathv[i]); if (len < 1) continue; if (g.gl_pathv[i][len - 1] == '/') continue; /* don't parse directories */ if (0 > fpm_conf_load_ini_file(g.gl_pathv[i])) { zlog(ZLOG_ERROR, "Unable to include %s from %s at line %d", g.gl_pathv[i], filename, ini_lineno); *error = 1; - efree(filename); return; } } php_globfree(&g); } - - efree(filename); } /* }}} */ diff --git a/sapi/phpdbg/phpdbg_prompt.c b/sapi/phpdbg/phpdbg_prompt.c index 84bd7a076acec..e797a696a4b06 100644 --- a/sapi/phpdbg/phpdbg_prompt.c +++ b/sapi/phpdbg/phpdbg_prompt.c @@ -111,7 +111,7 @@ static inline int phpdbg_call_register(phpdbg_param_t *stack) /* {{{ */ array_init(¶ms); while (next) { - char *buffered = NULL; + zend_string *buffered = NULL; switch (next->type) { case OP_PARAM: @@ -125,28 +125,28 @@ static inline int phpdbg_call_register(phpdbg_param_t *stack) /* {{{ */ break; case METHOD_PARAM: - spprintf(&buffered, 0, "%s::%s", next->method.class, next->method.name); - add_next_index_string(¶ms, buffered); + buffered = strpprintf(0, "%s::%s", next->method.class, next->method.name); + add_next_index_str(¶ms, buffered); break; case NUMERIC_METHOD_PARAM: - spprintf(&buffered, 0, "%s::%s#"ZEND_LONG_FMT, next->method.class, next->method.name, next->num); - add_next_index_string(¶ms, buffered); + buffered = strpprintf(0, "%s::%s#"ZEND_LONG_FMT, next->method.class, next->method.name, next->num); + add_next_index_str(¶ms, buffered); break; case NUMERIC_FUNCTION_PARAM: - spprintf(&buffered, 0, "%s#"ZEND_LONG_FMT, next->str, next->num); - add_next_index_string(¶ms, buffered); + buffered = strpprintf(0, "%s#"ZEND_LONG_FMT, next->str, next->num); + add_next_index_str(¶ms, buffered); break; case FILE_PARAM: - spprintf(&buffered, 0, "%s:"ZEND_ULONG_FMT, next->file.name, next->file.line); - add_next_index_string(¶ms, buffered); + buffered = strpprintf(0, "%s:"ZEND_ULONG_FMT, next->file.name, next->file.line); + add_next_index_str(¶ms, buffered); break; case NUMERIC_FILE_PARAM: - spprintf(&buffered, 0, "%s:#"ZEND_ULONG_FMT, next->file.name, next->file.line); - add_next_index_string(¶ms, buffered); + buffered = strpprintf(0, "%s:#"ZEND_ULONG_FMT, next->file.name, next->file.line); + add_next_index_str(¶ms, buffered); break; default: {