cvs: php4 /ext/standard string.c
| From: | Ilia Alshanetsky | Date: | Wed, 21 Aug 2002 13:14:57 +0000 |
| Subject: | cvs: php4 /ext/standard string.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-13530@lists.php.net to get a copy of this message | ||
iliaa Wed Aug 21 09:14:57 2002 EDT
Modified files:
/php4/ext/standard string.c
Log:
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.
Index: php4/ext/standard/string.c
diff -u php4/ext/standard/string.c:1.282 php4/ext/standard/string.c:1.283
--- php4/ext/standard/string.c:1.282 Wed Aug 21 02:22:19 2002
+++ php4/ext/standard/string.c Wed Aug 21 09:14:57 2002
@@ -18,7 +18,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: string.c,v 1.282 2002/08/21 06:22:19 sebastian Exp $ */
+/* $Id: string.c,v 1.283 2002/08/21 13:14:57 iliaa Exp $ */
/* Synced with php 3.0 revision 1.193 1999-06-16 [ssb] */
@@ -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 @@
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 @@
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);
}
/* }}} */