Skip to content

Commit efad70c

Browse files
author
Ilia Alshanetsky
committed
snprintf() -> slprintf()
1 parent cc04404 commit efad70c

File tree

18 files changed

+31
-28
lines changed

18 files changed

+31
-28
lines changed

ext/ftp/ftp.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1102,13 +1102,13 @@ ftp_putcmd(ftpbuf_t *ftp, const char *cmd, const char *args)
11021102
if (strlen(cmd) + strlen(args) + 4 > FTP_BUFSIZE) {
11031103
return 0;
11041104
}
1105-
size = snprintf(ftp->outbuf, sizeof(ftp->outbuf), "%s %s\r\n", cmd, args);
1105+
size = slprintf(ftp->outbuf, sizeof(ftp->outbuf), "%s %s\r\n", cmd, args);
11061106
} else {
11071107
/* "cmd\r\n\0" */
11081108
if (strlen(cmd) + 3 > FTP_BUFSIZE) {
11091109
return 0;
11101110
}
1111-
size = snprintf(ftp->outbuf, sizeof(ftp->outbuf), "%s\r\n", cmd);
1111+
size = slprintf(ftp->outbuf, sizeof(ftp->outbuf), "%s\r\n", cmd);
11121112
}
11131113

11141114
data = ftp->outbuf;

ext/hash/hash.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ PHP_MINFO_FUNCTION(hash)
588588
for(zend_hash_internal_pointer_reset_ex(&php_hash_hashtable, &pos);
589589
(type = zend_hash_get_current_key_ex(&php_hash_hashtable, &str, NULL, &idx, 0, &pos)) != HASH_KEY_NON_EXISTANT;
590590
zend_hash_move_forward_ex(&php_hash_hashtable, &pos)) {
591-
s += snprintf(s, e - s, "%s ", str);
591+
s += slprintf(s, e - s, "%s ", str);
592592
}
593593
*s = 0;
594594

ext/mbstring/oniguruma/regerror.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,9 @@ onig_snprintf_with_pattern(buf, bufsize, enc, pat, pat_end, fmt, va_alist)
278278

279279
va_init_list(args, fmt);
280280
n = vsnprintf((char* )buf, bufsize, (const char* )fmt, args);
281+
if (n >= bufsize) {
282+
return;
283+
}
281284
va_end(args);
282285

283286
need = (pat_end - pat) * 4 + 4;

ext/mhash/mhash.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ PHP_MINIT_FUNCTION(mhash)
7070

7171
for (i=0; i<n; i++) {
7272
if ((name = mhash_get_hash_name(i))) {
73-
l = snprintf(buf, 127, "MHASH_%s", name);
73+
l = slprintf(buf, 127, "MHASH_%s", name);
7474
zend_register_long_constant(buf, l + 1, i, CONST_PERSISTENT, module_number TSRMLS_CC);
7575
free(name);
7676
}

ext/pcre/pcrelib/pcregrep.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1188,7 +1188,7 @@ if ((sep = isdirectory(pathname)) != 0)
11881188
while ((nextfile = readdirectory(dir)) != NULL)
11891189
{
11901190
int frc, blen;
1191-
blen = snprintf(buffer, sizeof(buffer), "%.512s%c%.128s", pathname, sep, nextfile);
1191+
blen = slprintf(buffer, sizeof(buffer), "%.512s%c%.128s", pathname, sep, nextfile);
11921192

11931193
if (exclude_compiled != NULL &&
11941194
pcre_exec(exclude_compiled, NULL, buffer, blen, 0, 0, NULL, 0) >= 0)

ext/pdo_firebird/firebird_driver.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,7 @@ static int pdo_firebird_handle_factory(pdo_dbh_t *dbh, zval *driver_options TSRM
619619
/* loop through all the provided arguments and set dpb fields accordingly */
620620
for (i = 0; i < sizeof(dpb_flags); ++i) {
621621
if (dpb_values[i] && buf_len > 0) {
622-
dpb_len = snprintf(dpb, buf_len, "%c%c%s", dpb_flags[i], (unsigned char)strlen(dpb_values[i]),
622+
dpb_len = slprintf(dpb, buf_len, "%c%c%s", dpb_flags[i], (unsigned char)strlen(dpb_values[i]),
623623
dpb_values[i]);
624624
dpb += dpb_len;
625625
buf_len -= dpb_len;

ext/session/mod_mm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ PHP_MINIT_FUNCTION(ps_mm)
262262
return FAILURE;
263263
}
264264

265-
if (!(euid_len = snprintf(euid, sizeof(euid), "%d", geteuid()))) {
265+
if (!(euid_len = slprintf(euid, sizeof(euid), "%d", geteuid()))) {
266266
return FAILURE;
267267
}
268268

ext/session/session.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -950,7 +950,7 @@ static void strcpy_gmt(char *ubuf, time_t *when)
950950

951951
php_gmtime_r(when, &tm);
952952

953-
n = snprintf(buf, sizeof(buf), "%s, %02d %s %d %02d:%02d:%02d GMT", /* SAFE */
953+
n = slprintf(buf, sizeof(buf), "%s, %02d %s %d %02d:%02d:%02d GMT", /* SAFE */
954954
week_days[tm.tm_wday], tm.tm_mday,
955955
month_names[tm.tm_mon], tm.tm_year + 1900,
956956
tm.tm_hour, tm.tm_min,

ext/spl/spl_directory.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1642,7 +1642,7 @@ SPL_METHOD(SplTempFileObject, __construct)
16421642
intern->file_name = "php://memory";
16431643
intern->file_name_len = 12;
16441644
} else if (ZEND_NUM_ARGS()) {
1645-
intern->file_name_len = snprintf(tmp_fname, sizeof(tmp_fname), "php://temp/maxmemory:%ld", max_memory);
1645+
intern->file_name_len = slprintf(tmp_fname, sizeof(tmp_fname), "php://temp/maxmemory:%ld", max_memory);
16461646
intern->file_name = tmp_fname;
16471647
} else {
16481648
intern->file_name = "php://temp";

ext/spl/spl_iterators.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1390,7 +1390,7 @@ SPL_METHOD(RegexIterator, accept)
13901390

13911391
if (intern->u.regex.flags & REGIT_USE_KEY) {
13921392
if (intern->current.key_type == HASH_KEY_IS_LONG) {
1393-
subject_len = snprintf(tmp, sizeof(tmp), "%ld", intern->current.int_key);
1393+
subject_len = slprintf(tmp, sizeof(tmp), "%ld", intern->current.int_key);
13941394
subject = &tmp[0];
13951395
use_copy = 0;
13961396
} else {

ext/standard/html.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -912,7 +912,7 @@ PHPAPI char *php_unescape_html_entities(unsigned char *old, int oldlen, int *new
912912
if (entity_map[j].table[k - entity_map[j].basechar] == NULL)
913913
continue;
914914

915-
entity_length = snprintf(entity, sizeof(entity), "&%s;", entity_map[j].table[k - entity_map[j].basechar]);
915+
entity_length = slprintf(entity, sizeof(entity), "&%s;", entity_map[j].table[k - entity_map[j].basechar]);
916916
if (entity_length >= sizeof(entity)) {
917917
continue;
918918
}

ext/standard/http_fopen_wrapper.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ php_stream *php_stream_url_wrap_http_ex(php_stream_wrapper *wrapper, char *path,
438438
/* ensure the header is only sent if user_agent is not blank */
439439
if (ua_len > sizeof(_UA_HEADER)) {
440440
ua = emalloc(ua_len + 1);
441-
if ((ua_len = snprintf(ua, ua_len, _UA_HEADER, ua_str)) > 0) {
441+
if ((ua_len = slprintf(ua, ua_len, _UA_HEADER, ua_str)) > 0) {
442442
ua[ua_len] = 0;
443443
php_stream_write(stream, ua, ua_len);
444444
} else {
@@ -456,7 +456,7 @@ php_stream *php_stream_url_wrap_http_ex(php_stream_wrapper *wrapper, char *path,
456456
php_stream_context_get_option(context, "http", "content", &tmpzval) == SUCCESS &&
457457
Z_TYPE_PP(tmpzval) == IS_STRING && Z_STRLEN_PP(tmpzval) > 0) {
458458
if (!(have_header & HTTP_HEADER_CONTENT_LENGTH)) {
459-
scratch_len = snprintf(scratch, scratch_len, "Content-Length: %d\r\n", Z_STRLEN_PP(tmpzval));
459+
scratch_len = slprintf(scratch, scratch_len, "Content-Length: %d\r\n", Z_STRLEN_PP(tmpzval));
460460
php_stream_write(stream, scratch, scratch_len);
461461
}
462462
if (!(have_header & HTTP_HEADER_TYPE)) {

ext/standard/string.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -905,7 +905,7 @@ PHPAPI void php_implode(zval *delim, zval *arr, zval *return_value TSRMLS_DC)
905905

906906
case IS_LONG: {
907907
char stmp[MAX_LENGTH_OF_LONG + 1];
908-
str_len = snprintf(stmp, sizeof(stmp), "%ld", Z_LVAL_PP(tmp));
908+
str_len = slprintf(stmp, sizeof(stmp), "%ld", Z_LVAL_PP(tmp));
909909
smart_str_appendl(&implstr, stmp, str_len);
910910
}
911911
break;

ext/wddx/wddx.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ PS_SERIALIZER_DECODE_FUNC(wddx)
284284

285285
switch (hash_type) {
286286
case HASH_KEY_IS_LONG:
287-
key_length = snprintf(tmp, sizeof(tmp), "%ld", idx) + 1;
287+
key_length = slprintf(tmp, sizeof(tmp), "%ld", idx) + 1;
288288
key = tmp;
289289
/* fallthru */
290290
case HASH_KEY_IS_STRING:
@@ -501,7 +501,7 @@ static void php_wddx_serialize_object(wddx_packet *packet, zval *obj)
501501
zend_unmangle_property_name(key, key_len-1, &class_name, &prop_name);
502502
php_wddx_serialize_var(packet, *ent, prop_name, strlen(prop_name)+1 TSRMLS_CC);
503503
} else {
504-
key_len = snprintf(tmp_buf, sizeof(tmp_buf), "%ld", idx);
504+
key_len = slprintf(tmp_buf, sizeof(tmp_buf), "%ld", idx);
505505
php_wddx_serialize_var(packet, *ent, tmp_buf, key_len TSRMLS_CC);
506506
}
507507
}
@@ -572,7 +572,7 @@ static void php_wddx_serialize_array(wddx_packet *packet, zval *arr)
572572
if (ent_type == HASH_KEY_IS_STRING) {
573573
php_wddx_serialize_var(packet, *ent, key, key_len TSRMLS_CC);
574574
} else {
575-
key_len = snprintf(tmp_buf, sizeof(tmp_buf), "%ld", idx);
575+
key_len = slprintf(tmp_buf, sizeof(tmp_buf), "%ld", idx);
576576
php_wddx_serialize_var(packet, *ent, tmp_buf, key_len TSRMLS_CC);
577577
}
578578
} else

main/SAPI.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,7 @@ SAPI_API int sapi_header_op(sapi_header_op_enum op, void *arg TSRMLS_DC)
687687
/* If there is no realm string at all, append one */
688688
if(!strstr(lower_temp,"realm")) {
689689
efree(result);
690-
conv_len = snprintf(conv_temp, sizeof(conv_temp), " realm=\"%ld\"",myuid);
690+
conv_len = slprintf(conv_temp, sizeof(conv_temp), " realm=\"%ld\"",myuid);
691691
result = emalloc(ptr_len+conv_len+1);
692692
result_len = ptr_len+conv_len;
693693
memcpy(result, ptr, ptr_len);
@@ -774,7 +774,7 @@ SAPI_API int sapi_send_headers(TSRMLS_D)
774774

775775
assert(Z_STRVAL_P(uf_result) != NULL);
776776

777-
len = snprintf(buf, sizeof(buf), "Content-Encoding: %s", Z_STRVAL_P(uf_result));
777+
len = slprintf(buf, sizeof(buf), "Content-Encoding: %s", Z_STRVAL_P(uf_result));
778778
if (len <= 0 || sapi_add_header(buf, len, 1) == FAILURE) {
779779
return FAILURE;
780780
}
@@ -818,7 +818,7 @@ SAPI_API int sapi_send_headers(TSRMLS_D)
818818
http_status_line.header_len = strlen(SG(sapi_headers).http_status_line);
819819
} else {
820820
http_status_line.header = buf;
821-
http_status_line.header_len = snprintf(buf, sizeof(buf), "HTTP/1.0 %d X", SG(sapi_headers).http_response_code);
821+
http_status_line.header_len = slprintf(buf, sizeof(buf), "HTTP/1.0 %d X", SG(sapi_headers).http_response_code);
822822
}
823823
sapi_module.send_header(&http_status_line, SG(server_context) TSRMLS_CC);
824824
}

sapi/cgi/cgi_main.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -325,15 +325,15 @@ static int sapi_cgi_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC)
325325
int len;
326326

327327
if (CGIG(rfc2616_headers) && SG(sapi_headers).http_status_line) {
328-
len = snprintf(buf, SAPI_CGI_MAX_HEADER_LENGTH,
328+
len = slprintf(buf, SAPI_CGI_MAX_HEADER_LENGTH,
329329
"%s\r\n", SG(sapi_headers).http_status_line);
330330

331331
if (len > SAPI_CGI_MAX_HEADER_LENGTH) {
332332
len = SAPI_CGI_MAX_HEADER_LENGTH;
333333
}
334334

335335
} else {
336-
len = snprintf(buf, sizeof(buf), "Status: %d\r\n", SG(sapi_headers).http_response_code);
336+
len = slprintf(buf, sizeof(buf), "Status: %d\r\n", SG(sapi_headers).http_response_code);
337337
}
338338

339339
PHPWRITE_H(buf, len);
@@ -444,13 +444,13 @@ static char *_sapi_cgibin_putenv(char *name, char *value TSRMLS_DC)
444444
#endif
445445
#if !HAVE_SETENV
446446
if (value) {
447-
len = snprintf(buf, len - 1, "%s=%s", name, value);
447+
len = slprintf(buf, len - 1, "%s=%s", name, value);
448448
putenv(buf);
449449
}
450450
#endif
451451
#if !HAVE_UNSETENV
452452
if (!value) {
453-
len = snprintf(buf, len - 1, "%s=", name);
453+
len = slprintf(buf, len - 1, "%s=", name);
454454
putenv(buf);
455455
}
456456
#endif

sapi/cgi/fastcgi.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -588,8 +588,8 @@ static int fcgi_read_request(fcgi_request *req)
588588

589589
for (j = 0; j < sizeof(fcgi_mgmt_vars)/sizeof(fcgi_mgmt_vars[0]); j++) {
590590
if (zend_hash_exists(&req->env, fcgi_mgmt_vars[j].name, fcgi_mgmt_vars[j].name_len+1) == 0) {
591-
sprintf((char*)p, "%c%c%s%c", fcgi_mgmt_vars[j].name_len, 1, fcgi_mgmt_vars[j].name, fcgi_mgmt_vars[j].val);
592-
p += fcgi_mgmt_vars[j].name_len + 3;
591+
sprintf((char*)p, "%c%c%s%c", fcgi_mgmt_vars[j].name_len, 1, fcgi_mgmt_vars[j].name, fcgi_mgmt_vars[j].val);
592+
p += fcgi_mgmt_vars[j].name_len + 3;
593593
}
594594
}
595595
len = p - buf - sizeof(fcgi_header);

sapi/tux/php_tux.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ static int sapi_tux_send_headers(sapi_headers_struct *sapi_headers)
116116
status_line = malloc(30);
117117

118118
/* safe sprintf use */
119-
len = snprintf(status_line, 30, "HTTP/1.1 %d NA\r\n", SG(sapi_headers).http_response_code);
119+
len = slprintf(status_line, 30, "HTTP/1.1 %d NA\r\n", SG(sapi_headers).http_response_code);
120120

121121
vec[0].iov_base = status_line;
122122
vec[0].iov_len = len;
@@ -195,7 +195,7 @@ static void sapi_tux_register_variables(zval *track_vars_array TSRMLS_DC)
195195
sapi_header_line ctr = {0};
196196

197197
ctr.line = buf;
198-
ctr.line_len = snprintf(buf, sizeof(buf), "Server: %s", TUXAPI_version);
198+
ctr.line_len = slprintf(buf, sizeof(buf), "Server: %s", TUXAPI_version);
199199
sapi_header_op(SAPI_HEADER_REPLACE, &ctr TSRMLS_CC);
200200

201201
php_register_variable("PHP_SELF", SG(request_info).request_uri, track_vars_array TSRMLS_CC);

0 commit comments

Comments
 (0)