- use sizeof() for snprintf
authorMichael Wallner <mike@php.net>
Mon, 15 Jan 2007 07:59:41 +0000 (07:59 +0000)
committerMichael Wallner <mike@php.net>
Mon, 15 Jan 2007 07:59:41 +0000 (07:59 +0000)
http_cache_api.c
http_date_api.c
http_encoding_api.c
http_request_api.c
http_send_api.c
http_url_api.c

index f7f0c816e23a67ef4b55c2e1134a8fb36b900812..b6c4fad5963ca79fa7041cbcf7080fb8094d1f14 100644 (file)
@@ -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);
index 66033262bbc3ba5f73e3bb7a0d1b951aaaf0e87a..e750a4da49863cec0d1077bd580ba5073dd84309 100644 (file)
@@ -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;
 }
 /* }}} */
 
index 2d20908951ce01c37e1b13d9e3b6ba2a4d4a1aeb..48fe773ac2b078c1882f79bfce22d74eee3621c3 100644 (file)
@@ -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;
index 0dfce3c5b0d903f5f9b7ffd14251bccc37d92428..6528b97d303c843eab4220bd81a557755f6ac10a 100644 (file)
@@ -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(&quoted_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);
        }
index 7be1968e18b3b76fa88d18e5d9f084c9e0ee81d6..76c60a4f9328912e0a5e9f2ee5f95a9a309534d2 100644 (file)
@@ -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);
                                        }
index 37c23cd6910f6b0e2dce4b64095fcc7d28e12f1f..1cd5bd472d95a99f6b28878d425debed9f3bed2f 100644 (file)
@@ -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);
                }