tree: replace some unnecessary uses of spprintf (#19354)

This commit is contained in:
Gina Peter Banyard 2025-08-05 17:25:47 +01:00 committed by GitHub
parent 0596135d20
commit d9000b3094
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 34 additions and 38 deletions

View file

@ -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);

View file

@ -638,13 +638,9 @@ finish:
/* 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");
}

View file

@ -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);
}
}

View file

@ -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 = '-';

View file

@ -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);
}
/* }}} */

View file

@ -111,7 +111,7 @@ static inline int phpdbg_call_register(phpdbg_param_t *stack) /* {{{ */
array_init(&params);
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(&params, buffered);
buffered = strpprintf(0, "%s::%s", next->method.class, next->method.name);
add_next_index_str(&params, 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(&params, buffered);
buffered = strpprintf(0, "%s::%s#"ZEND_LONG_FMT, next->method.class, next->method.name, next->num);
add_next_index_str(&params, buffered);
break;
case NUMERIC_FUNCTION_PARAM:
spprintf(&buffered, 0, "%s#"ZEND_LONG_FMT, next->str, next->num);
add_next_index_string(&params, buffered);
buffered = strpprintf(0, "%s#"ZEND_LONG_FMT, next->str, next->num);
add_next_index_str(&params, buffered);
break;
case FILE_PARAM:
spprintf(&buffered, 0, "%s:"ZEND_ULONG_FMT, next->file.name, next->file.line);
add_next_index_string(&params, buffered);
buffered = strpprintf(0, "%s:"ZEND_ULONG_FMT, next->file.name, next->file.line);
add_next_index_str(&params, buffered);
break;
case NUMERIC_FILE_PARAM:
spprintf(&buffered, 0, "%s:#"ZEND_ULONG_FMT, next->file.name, next->file.line);
add_next_index_string(&params, buffered);
buffered = strpprintf(0, "%s:#"ZEND_ULONG_FMT, next->file.name, next->file.line);
add_next_index_str(&params, buffered);
break;
default: {