diff options
author | Ilia Alshanetsky <iliaa@php.net> | 2002-08-21 13:14:57 +0000 |
---|---|---|
committer | Ilia Alshanetsky <iliaa@php.net> | 2002-08-21 13:14:57 +0000 |
commit | ea1bb5e17293dc51856a814a8ef59f92059bd848 (patch) | |
tree | 072624fe6fadcd6f2ae1c019863308f0a781fa19 /ext/standard/string.c | |
parent | 116b06d6a58da55fee17f7c8f210c7fd60405c9c (diff) | |
download | php-git-ea1bb5e17293dc51856a814a8ef59f92059bd848.tar.gz |
Added monetary.h to prevent compile warning.
Fixed a memory leak inside money_format function, which occures if the
parameters to the function are not valid.
Fixed a segmentation fault inside money_format in the event the value
to be formated is >1024 bytes.
Made the return value of money_format be null terminated.
Diffstat (limited to 'ext/standard/string.c')
-rw-r--r-- | ext/standard/string.c | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/ext/standard/string.c b/ext/standard/string.c index 48f87e02b3..7da32a9ec3 100644 --- a/ext/standard/string.c +++ b/ext/standard/string.c @@ -33,6 +33,9 @@ #ifdef HAVE_LANGINFO_H # include <langinfo.h> #endif +#ifdef HAVE_MONETARY_H +# include <monetary.h> +#endif #include "scanf.h" #include "zend_API.h" #include "zend_execute.h" @@ -3909,8 +3912,8 @@ PHP_FUNCTION(str_rot13) Convert monetary value(s) to string */ PHP_FUNCTION(money_format) { - int format_len, str_len = 1024; - char *format, *str = emalloc(str_len); + int format_len = 0, str_len; + char *format, *str; double value; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sd", @@ -3918,9 +3921,12 @@ PHP_FUNCTION(money_format) { return; } + str_len = format_len + 1024; + str = emalloc(str_len); str_len = strfmon(str, str_len, format, value); + str[str_len] = 0; - RETURN_STRINGL(erealloc(str, strlen), str_len, 0); + RETURN_STRINGL(erealloc(str, str_len + 1), str_len, 0); } /* }}} */ |