summaryrefslogtreecommitdiff
path: root/ext/standard/formatted_print.c
diff options
context:
space:
mode:
authorMoriyoshi Koizumi <moriyoshi@php.net>2003-02-15 15:57:31 +0000
committerMoriyoshi Koizumi <moriyoshi@php.net>2003-02-15 15:57:31 +0000
commitb069f35022ae98682380e2fa3858569ea1d8c553 (patch)
treea4b0d424601d5070e868a816fb9b88a5995cb3e7 /ext/standard/formatted_print.c
parentecaeb3004adff86ba08ecab028669cd1e69c8cce (diff)
downloadphp-git-b069f35022ae98682380e2fa3858569ea1d8c553.tar.gz
Fixed bug #22227
Added test case for bug #22227
Diffstat (limited to 'ext/standard/formatted_print.c')
-rw-r--r--ext/standard/formatted_print.c23
1 files changed, 11 insertions, 12 deletions
diff --git a/ext/standard/formatted_print.c b/ext/standard/formatted_print.c
index b53d5e3072..67915bed65 100644
--- a/ext/standard/formatted_print.c
+++ b/ext/standard/formatted_print.c
@@ -158,12 +158,11 @@ php_sprintf_appendstring(char **buffer, int *pos, int *size, char *add,
int alignment, int len, int sign, int expprec)
{
register int npad;
+ int req_size;
+ int copy_len;
- if (max_width && min_width) {
- expprec = max_width = 0;
- }
-
- npad = min_width - MIN(len, (expprec ? max_width : len));
+ copy_len = (expprec ? MIN(max_width, len) : len);
+ npad = min_width - copy_len;
if (npad < 0) {
npad = 0;
@@ -171,11 +170,11 @@ php_sprintf_appendstring(char **buffer, int *pos, int *size, char *add,
PRINTF_DEBUG(("sprintf: appendstring(%x, %d, %d, \"%s\", %d, '%c', %d)\n",
*buffer, *pos, *size, add, min_width, padding, alignment));
- if ((max_width == 0) && (! expprec)) {
- max_width = MAX(min_width, len);
- }
- if ((*pos + max_width) >= *size) {
- while ((*pos + max_width) >= *size) {
+
+ req_size = *pos + MAX(min_width, copy_len) + 1;
+
+ if (req_size > *size) {
+ while (req_size > *size) {
*size <<= 1;
}
PRINTF_DEBUG(("sprintf ereallocing buffer to %d bytes\n", *size));
@@ -192,8 +191,8 @@ php_sprintf_appendstring(char **buffer, int *pos, int *size, char *add,
}
}
PRINTF_DEBUG(("sprintf: appending \"%s\"\n", add));
- memcpy(&(*buffer)[*pos], add, MIN(max_width, len)+1);
- *pos += MIN(max_width, len);
+ memcpy(&(*buffer)[*pos], add, copy_len + 1);
+ *pos += copy_len;
if (alignment == ALIGN_LEFT) {
while (npad--) {
(*buffer)[(*pos)++] = padding;