I just implemented spprintf and vpprintf.

Both are nearly the same as (v)snprintf. The difference is that using vspprintf you
usee a dynamically allocated buffer which *can* have a maximum length. To reduce
runtime cost the functions reallocate in buffers of 1K. The old value of *pbuf is ignored
and set NULL on initialisation failure. If during a call not enough memory could be
allocated you will not be modified (maybe i add a parameter for that). The result
is the length as with (v)snprintf. If *pbuf != NULL you have to call
efree(*pbuf).

extern int spprintf( char **pbuf, size_t max_len, const char *format, ...);

extern int vspprintf(char **pbuf, size_t max_len, const char *format, va_list ap);

Currentls i used it to fix a problem in ext/exif and to have error_logs allowing longer
messages by ini setting.

I searched through the code and found many calls to (v)snprintf includeing those using
php_printf. As php_printf is a replacement for printf i suggest we implement that function
using vspprintf, too. But i could not test yet. So here is the diff on that:

cvs -z3 -q diff main.c (in directory S:\php4\main\)
Index: main.c
===================================================================
RCS file: /repository/php4/main/main.c,v
retrieving revision 1.443
diff -u -r1.443 main.c
--- main.c      10 Apr 2002 01:27:44 -0000      1.443
+++ main.c      10 Apr 2002 01:41:19 -0000
@@ -357,16 +357,18 @@
 {
        va_list args;
        int ret;
-       char buffer[PRINTF_BUFFER_SIZE];
+       char *buffer;
        int size;
        TSRMLS_FETCH();
 
        va_start(args, format);
-       size = vsnprintf(buffer, sizeof(buffer), format, args);
-       if(size > sizeof(buffer) - 1) {
-               size = sizeof(buffer) - 1;
+       size = vspprintf(&buffer, 0, format, args);
+       if (buffer) {
+               ret = PHPWRITE(buffer, size);
+               efree(buffer);
+       } else {
+               ret = 0;
        }
-       ret = PHPWRITE(buffer, size);
        va_end(args);
        
        return ret;



marcus


--------->>> mailto:[EMAIL PROTECTED] <<<------------
        I don't want to start any blashphemous rumours
        but i think that god's got a sick sense of humor
        and when i die i expect to find him laughing.
                                             Depeche Mode
--------------->>> http://www.marcus-boerger.de <<<-------------------

Reply via email to