Skip to content

Commit b1c9d5d

Browse files
committed
Use strpprintf
1 parent 88c550a commit b1c9d5d

File tree

4 files changed

+23
-26
lines changed

4 files changed

+23
-26
lines changed

ext/pdo/pdo_dbh.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ PDO_API void pdo_handle_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt TSRMLS_DC) /* {{{
104104
const char *msg = "<<Unknown>>";
105105
char *supp = NULL;
106106
long native_code = 0;
107-
char *message = NULL;
107+
zend_string *message = NULL;
108108
zval info;
109109

110110
if (dbh == NULL || dbh->error_mode == PDO_ERRMODE_SILENT) {
@@ -141,20 +141,20 @@ PDO_API void pdo_handle_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt TSRMLS_DC) /* {{{
141141
}
142142

143143
if (supp) {
144-
spprintf(&message, 0, "SQLSTATE[%s]: %s: %ld %s", *pdo_err, msg, native_code, supp);
144+
message = strpprintf(0, "SQLSTATE[%s]: %s: %ld %s", *pdo_err, msg, native_code, supp);
145145
} else {
146-
spprintf(&message, 0, "SQLSTATE[%s]: %s", *pdo_err, msg);
146+
message = strpprintf(0, "SQLSTATE[%s]: %s", *pdo_err, msg);
147147
}
148148

149149
if (dbh->error_mode == PDO_ERRMODE_WARNING) {
150-
php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", message);
150+
php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", message->val);
151151
} else if (EG(exception) == NULL) {
152152
zval ex;
153153
zend_class_entry *def_ex = php_pdo_get_exception_base(1 TSRMLS_CC), *pdo_ex = php_pdo_get_exception();
154154

155155
object_init_ex(&ex, pdo_ex);
156156

157-
zend_update_property_string(def_ex, &ex, "message", sizeof("message") - 1, message TSRMLS_CC);
157+
zend_update_property_str(def_ex, &ex, "message", sizeof("message") - 1, message TSRMLS_CC);
158158
zend_update_property_string(def_ex, &ex, "code", sizeof("code") - 1, *pdo_err TSRMLS_CC);
159159

160160
if (!Z_ISUNDEF(info)) {
@@ -169,7 +169,7 @@ PDO_API void pdo_handle_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt TSRMLS_DC) /* {{{
169169
}
170170

171171
if (message) {
172-
efree(message);
172+
STR_RELEASE(message);
173173
}
174174

175175
if (supp) {

ext/standard/fsock.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ PHP_FUNCTION(fsockopen)
126126
php_fsockopen_stream(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
127127
}
128128
/* }}} */
129+
129130
/* {{{ proto resource pfsockopen(string hostname, int port [, int errno [, string errstr [, float timeout]]])
130131
Open persistent Internet or Unix domain socket connection */
131132
PHP_FUNCTION(pfsockopen)

ext/standard/math.c

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,11 +1063,11 @@ PHPAPI zend_string *_php_math_number_format_ex(double d, int dec, char *dec_poin
10631063
size_t dec_point_len, char *thousand_sep, size_t thousand_sep_len)
10641064
{
10651065
zend_string *res;
1066-
char *tmpbuf;
1066+
zend_string *tmpbuf;
10671067
char *s, *t; /* source, target */
10681068
char *dp;
10691069
int integral;
1070-
int tmplen, reslen = 0;
1070+
int reslen = 0;
10711071
int count = 0;
10721072
int is_negative=0;
10731073

@@ -1078,28 +1078,26 @@ PHPAPI zend_string *_php_math_number_format_ex(double d, int dec, char *dec_poin
10781078

10791079
dec = MAX(0, dec);
10801080
d = _php_math_round(d, dec, PHP_ROUND_HALF_UP);
1081-
tmplen = spprintf(&tmpbuf, 0, "%.*F", dec, d);
1081+
tmpbuf = strpprintf(0, "%.*F", dec, d);
10821082
if (tmpbuf == NULL) {
10831083
return NULL;
1084-
} else if (!isdigit((int)tmpbuf[0])) {
1085-
res = STR_INIT(tmpbuf, tmplen, 0);
1086-
efree(tmpbuf);
1087-
return res;
1084+
} else if (!isdigit((int)tmpbuf->val[0])) {
1085+
return tmpbuf;
10881086
}
10891087

10901088
/* find decimal point, if expected */
10911089
if (dec) {
1092-
dp = strpbrk(tmpbuf, ".,");
1090+
dp = strpbrk(tmpbuf->val, ".,");
10931091
} else {
10941092
dp = NULL;
10951093
}
10961094

10971095
/* calculate the length of the return buffer */
10981096
if (dp) {
1099-
integral = dp - tmpbuf;
1097+
integral = dp - tmpbuf->val;
11001098
} else {
11011099
/* no decimal point was found */
1102-
integral = tmplen;
1100+
integral = tmpbuf->len;
11031101
}
11041102

11051103
/* allow for thousand separators */
@@ -1123,7 +1121,7 @@ PHPAPI zend_string *_php_math_number_format_ex(double d, int dec, char *dec_poin
11231121
}
11241122
res = STR_ALLOC(reslen, 0);
11251123

1126-
s = tmpbuf + tmplen - 1;
1124+
s = tmpbuf->val + tmpbuf->len - 1;
11271125
t = res->val + reslen;
11281126
*t-- = '\0';
11291127

@@ -1156,9 +1154,9 @@ PHPAPI zend_string *_php_math_number_format_ex(double d, int dec, char *dec_poin
11561154

11571155
/* copy the numbers before the decimal point, adding thousand
11581156
* separator every three digits */
1159-
while(s >= tmpbuf) {
1157+
while (s >= tmpbuf->val) {
11601158
*t-- = *s--;
1161-
if (thousand_sep && (++count%3)==0 && s>=tmpbuf) {
1159+
if (thousand_sep && (++count%3)==0 && s>=tmpbuf->val) {
11621160
t -= thousand_sep_len;
11631161
memcpy(t + 1, thousand_sep, thousand_sep_len);
11641162
}
@@ -1170,7 +1168,7 @@ PHPAPI zend_string *_php_math_number_format_ex(double d, int dec, char *dec_poin
11701168
}
11711169

11721170
res->len = reslen;
1173-
efree(tmpbuf);
1171+
STR_RELEASE(tmpbuf);
11741172
return res;
11751173
}
11761174

ext/standard/uniqid.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ PHP_FUNCTION(uniqid)
4949
#else
5050
zend_bool more_entropy = 0;
5151
#endif
52-
char *uniqid;
52+
zend_string *uniqid;
5353
int sec, usec, prefix_len = 0;
5454
struct timeval tv;
5555

@@ -76,14 +76,12 @@ PHP_FUNCTION(uniqid)
7676
* digits for usecs.
7777
*/
7878
if (more_entropy) {
79-
spprintf(&uniqid, 0, "%s%08x%05x%.8F", prefix, sec, usec, php_combined_lcg(TSRMLS_C) * 10);
79+
uniqid = strpprintf(0, "%s%08x%05x%.8F", prefix, sec, usec, php_combined_lcg(TSRMLS_C) * 10);
8080
} else {
81-
spprintf(&uniqid, 0, "%s%08x%05x", prefix, sec, usec);
81+
uniqid = strpprintf(0, "%s%08x%05x", prefix, sec, usec);
8282
}
8383

84-
// TODO: avoid reallocation ???
85-
RETVAL_STRING(uniqid);
86-
efree(uniqid);
84+
RETURN_STR(uniqid);
8785
}
8886
#endif
8987
/* }}} */

0 commit comments

Comments
 (0)