From: Michael Wallner Date: Mon, 15 Jan 2007 07:59:41 +0000 (+0000) Subject: - use sizeof() for snprintf X-Git-Tag: RELEASE_1_4_0RC2~5 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=b51b3809f61db4904df3b9c034bbde879732f0b9;p=m6w6%2Fext-http - use sizeof() for snprintf --- diff --git a/http_cache_api.c b/http_cache_api.c index f7f0c81..b6c4fad 100644 --- a/http_cache_api.c +++ b/http_cache_api.c @@ -45,9 +45,9 @@ PHP_HTTP_API char *_http_etag(const void *data_ptr, size_t data_len, http_send_m return NULL; } else { size_t ssb_len; - char ssb_buf[128] = {0}; + char ssb_buf[128]; - ssb_len = snprintf(ssb_buf, 127, "%ld=%ld=%ld", (long) ssb.sb.st_mtime, + ssb_len = snprintf(ssb_buf, sizeof(ssb_buf), "%ld=%ld=%ld", (long) ssb.sb.st_mtime, (long) ssb.sb.st_ino, (long) ssb.sb.st_size); http_etag_update(ctx, ssb_buf, ssb_len); diff --git a/http_date_api.c b/http_date_api.c index 6603326..e750a4d 100644 --- a/http_date_api.c +++ b/http_date_api.c @@ -141,20 +141,19 @@ static inline int check_tzone(const char *tzone) /* {{{ char *http_date(time_t) */ PHP_HTTP_API char *_http_date(time_t t TSRMLS_DC) { + char *date = NULL; struct tm *gmtime, tmbuf; if ((gmtime = php_gmtime_r(&t, &tmbuf))) { - char *date = ecalloc(1, 31); - snprintf(date, 30, + spprintf(&date, 0, "%s, %02d %s %04d %02d:%02d:%02d GMT", days[gmtime->tm_wday], gmtime->tm_mday, months[gmtime->tm_mon], gmtime->tm_year + 1900, gmtime->tm_hour, gmtime->tm_min, gmtime->tm_sec ); - return date; } - return NULL; + return date; } /* }}} */ diff --git a/http_encoding_api.c b/http_encoding_api.c index 2d20908..48fe773 100644 --- a/http_encoding_api.c +++ b/http_encoding_api.c @@ -213,7 +213,7 @@ PHP_HTTP_API int _http_encoding_response_start(size_t content_length, zend_bool /* emit a content-length header */ char cl_header_str[128]; size_t cl_header_len; - cl_header_len = snprintf(cl_header_str, lenof(cl_header_str), "Content-Length: %zu", content_length); + cl_header_len = snprintf(cl_header_str, sizeof(cl_header_str), "Content-Length: %zu", content_length); http_send_header_string_ex(cl_header_str, cl_header_len, 1); } else { HTTP_G->send.deflate.encoding = 0; diff --git a/http_request_api.c b/http_request_api.c index 0dfce3c..6528b97 100644 --- a/http_request_api.c +++ b/http_request_api.c @@ -639,14 +639,14 @@ PHP_HTTP_API STATUS _http_request_prepare(http_request *request, HashTable *opti FOREACH_KEYVAL(pos, zoption, header_key, header_val) { if (header_key.type == HASH_KEY_IS_STRING) { - char header[1024] = {0}; + char header[1024]; ZVAL_ADDREF(*header_val); convert_to_string_ex(header_val); if (!strcasecmp(header_key.str, "range")) { range_req = 1; } - snprintf(header, lenof(header), "%s: %s", header_key.str, Z_STRVAL_PP(header_val)); + snprintf(header, sizeof(header), "%s: %s", header_key.str, Z_STRVAL_PP(header_val)); request->_cache.headers = curl_slist_append(request->_cache.headers, header); zval_ptr_dtor(header_val); } @@ -654,12 +654,12 @@ PHP_HTTP_API STATUS _http_request_prepare(http_request *request, HashTable *opti } /* etag */ if ((zoption = http_request_option(request, options, "etag", IS_STRING)) && Z_STRLEN_P(zoption)) { - char match_header[1024] = {0}, *quoted_etag = NULL; + char match_header[1024], *quoted_etag = NULL; if ((Z_STRVAL_P(zoption)[0] != '"') || (Z_STRVAL_P(zoption)[Z_STRLEN_P(zoption)-1] != '"')) { spprintf("ed_etag, 0, "\"%s\"", Z_STRVAL_P(zoption)); } - snprintf(match_header, lenof(match_header), "%s: %s", range_req?"If-Match":"If-None-Match", quoted_etag?quoted_etag:Z_STRVAL_P(zoption)); + snprintf(match_header, sizeof(match_header), "%s: %s", range_req?"If-Match":"If-None-Match", quoted_etag?quoted_etag:Z_STRVAL_P(zoption)); request->_cache.headers = curl_slist_append(request->_cache.headers, match_header); STR_FREE(quoted_etag); } diff --git a/http_send_api.c b/http_send_api.c index 7be1968..76c60a4 100644 --- a/http_send_api.c +++ b/http_send_api.c @@ -404,7 +404,7 @@ PHP_HTTP_API STATUS _http_send_ex(const void *data_ptr, size_t data_size, http_s char range_header_str[256]; size_t range_header_len; - range_header_len = snprintf(range_header_str, lenof(range_header_str), "Content-Range: bytes %ld-%ld/%zu", Z_LVAL_PP(begin), Z_LVAL_PP(end), data_size); + range_header_len = snprintf(range_header_str, sizeof(range_header_str), "Content-Range: bytes %ld-%ld/%zu", Z_LVAL_PP(begin), Z_LVAL_PP(end), data_size); http_send_status_header_ex(206, range_header_str, range_header_len, 1); http_send_response_start(&s, Z_LVAL_PP(end)-Z_LVAL_PP(begin)+1); http_send_response_data_fetch(&s, data_ptr, data_size, data_mode, Z_LVAL_PP(begin), Z_LVAL_PP(end) + 1); @@ -420,8 +420,8 @@ PHP_HTTP_API STATUS _http_send_ex(const void *data_ptr, size_t data_size, http_s char boundary_str[32], range_header_str[256]; size_t boundary_len, range_header_len; - boundary_len = snprintf(boundary_str, lenof(boundary_str), "%lu%0.9f", (ulong) HTTP_G->request.time, (float) php_combined_lcg(TSRMLS_C)); - range_header_len = snprintf(range_header_str, lenof(range_header_str), "Content-Type: multipart/byteranges; boundary=%s", boundary_str); + boundary_len = snprintf(boundary_str, sizeof(boundary_str), "%lu%0.9f", (ulong) HTTP_G->request.time, (float) php_combined_lcg(TSRMLS_C)); + range_header_len = snprintf(range_header_str, sizeof(range_header_str), "Content-Type: multipart/byteranges; boundary=%s", boundary_str); http_send_status_header_ex(206, range_header_str, range_header_len, 1); http_send_response_start(&s, 0); @@ -442,7 +442,7 @@ PHP_HTTP_API STATUS _http_send_ex(const void *data_ptr, size_t data_size, http_s HTTP_CRLF "Content-Range: bytes %ld-%ld/%zu" \ HTTP_CRLF HTTP_CRLF - preface_len = snprintf(preface_str, lenof(preface_str), HTTP_RANGE_PREFACE, boundary_str, content_type, Z_LVAL_PP(begin), Z_LVAL_PP(end), data_size); + preface_len = snprintf(preface_str, sizeof(preface_str), HTTP_RANGE_PREFACE, boundary_str, content_type, Z_LVAL_PP(begin), Z_LVAL_PP(end), data_size); http_send_response_data_plain(&s, preface_str, preface_len); http_send_response_data_fetch(&s, data_ptr, data_size, data_mode, Z_LVAL_PP(begin), Z_LVAL_PP(end) + 1); } diff --git a/http_url_api.c b/http_url_api.c index 37c23cd..1cd5bd4 100644 --- a/http_url_api.c +++ b/http_url_api.c @@ -306,9 +306,9 @@ PHP_HTTP_API void _http_build_url(int flags, const php_url *old_url, const php_u strlcat(*url_str, url->host, HTTP_URL_MAXLEN); if (url->port) { - char port_str[8] = {0}; + char port_str[8]; - snprintf(port_str, lenof(port_str), "%d", (int) url->port); + snprintf(port_str, sizeof(port_str), "%d", (int) url->port); strlcat(*url_str, ":", HTTP_URL_MAXLEN); strlcat(*url_str, port_str, HTTP_URL_MAXLEN); }