Skip to content

tree: replace some unnecessary uses of spprintf #19354

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
12 changes: 7 additions & 5 deletions ext/pdo_pgsql/pgsql_statement.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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);
Expand Down
6 changes: 1 addition & 5 deletions ext/standard/http_fopen_wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down
8 changes: 5 additions & 3 deletions ext/sysvmsg/sysvmsg.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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);
}
}
Expand Down
9 changes: 5 additions & 4 deletions main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1079,7 +1079,8 @@ PHPAPI ZEND_COLD void php_verror(const char *docref, const char *params, int typ
if (is_function) {
origin_len = (int)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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I think origin_len should be a size_t.

origin = estrndup(function, origin_len);
}

if (PG(html_errors)) {
Expand All @@ -1096,14 +1097,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 = '-';
Expand Down
11 changes: 3 additions & 8 deletions sapi/fpm/fpm/fpm_conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -1383,46 +1383,41 @@ 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;
if ((i = php_glob(inc, PHP_GLOB_ERR | PHP_GLOB_MARK, NULL, &g)) != 0) {
#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);
}
/* }}} */

Expand Down
22 changes: 11 additions & 11 deletions sapi/phpdbg/phpdbg_prompt.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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: {
Expand Down