Skip to content

Commit b508988

Browse files
committed
Unbreak PRINTF_DEBUG macro usages
Clearly nobody has used this in a while given the compile errors and warnings. This patch fixes them so there are no errors nor warnings anymore. Closes phpGH-18910.
1 parent 2ccd2b0 commit b508988

File tree

1 file changed

+25
-21
lines changed

1 file changed

+25
-21
lines changed

ext/standard/formatted_print.c

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ inline static void
5252
php_sprintf_appendchar(zend_string **buffer, size_t *pos, char add)
5353
{
5454
if ((*pos + 1) >= ZSTR_LEN(*buffer)) {
55-
PRINTF_DEBUG(("%s(): ereallocing buffer to %d bytes\n", get_active_function_name(), ZSTR_LEN(*buffer)));
55+
PRINTF_DEBUG(("%s(): ereallocing buffer to %zu bytes\n", get_active_function_name(), ZSTR_LEN(*buffer)));
5656
*buffer = zend_string_extend(*buffer, ZSTR_LEN(*buffer) << 1, 0);
5757
}
58-
PRINTF_DEBUG(("sprintf: appending '%c', pos=\n", add, *pos));
58+
PRINTF_DEBUG(("sprintf: appending '%c', pos=%zu\n", add, *pos));
5959
ZSTR_VAL(*buffer)[(*pos)++] = add;
6060
}
6161
/* }}} */
@@ -67,13 +67,13 @@ php_sprintf_appendchars(zend_string **buffer, size_t *pos, char *add, size_t len
6767
if ((*pos + len) >= ZSTR_LEN(*buffer)) {
6868
size_t nlen = ZSTR_LEN(*buffer);
6969

70-
PRINTF_DEBUG(("%s(): ereallocing buffer to %d bytes\n", get_active_function_name(), ZSTR_LEN(*buffer)));
70+
PRINTF_DEBUG(("%s(): ereallocing buffer to %zu bytes\n", get_active_function_name(), ZSTR_LEN(*buffer)));
7171
do {
7272
nlen = nlen << 1;
7373
} while ((*pos + len) >= nlen);
7474
*buffer = zend_string_extend(*buffer, nlen, 0);
7575
}
76-
PRINTF_DEBUG(("sprintf: appending \"%s\", pos=\n", add, *pos));
76+
PRINTF_DEBUG(("sprintf: appending \"%s\", pos=%zu\n", add, *pos));
7777
memcpy(ZSTR_VAL(*buffer) + (*pos), add, len);
7878
*pos += len;
7979
}
@@ -93,7 +93,7 @@ php_sprintf_appendstring(zend_string **buffer, size_t *pos, char *add,
9393
copy_len = (expprec ? MIN(max_width, len) : len);
9494
npad = (min_width < copy_len) ? 0 : min_width - copy_len;
9595

96-
PRINTF_DEBUG(("sprintf: appendstring(%x, %d, %d, \"%s\", %d, '%c', %d)\n",
96+
PRINTF_DEBUG(("sprintf: appendstring(%p, %zu, %zu, \"%s\", %zu, '%c', %zu)\n",
9797
*buffer, *pos, ZSTR_LEN(*buffer), add, min_width, padding, alignment));
9898
m_width = MAX(min_width, copy_len);
9999

@@ -111,7 +111,7 @@ php_sprintf_appendstring(zend_string **buffer, size_t *pos, char *add,
111111
}
112112
size <<= 1;
113113
}
114-
PRINTF_DEBUG(("sprintf ereallocing buffer to %d bytes\n", size));
114+
PRINTF_DEBUG(("sprintf ereallocing buffer to %zu bytes\n", size));
115115
*buffer = zend_string_extend(*buffer, size, 0);
116116
}
117117
if (alignment == ALIGN_RIGHT) {
@@ -146,8 +146,8 @@ php_sprintf_appendint(zend_string **buffer, size_t *pos, zend_long number,
146146
zend_ulong magn, nmagn;
147147
unsigned int i = NUM_BUF_SIZE - 1, neg = 0;
148148

149-
PRINTF_DEBUG(("sprintf: appendint(%x, %x, %x, %d, %d, '%c', %d)\n",
150-
*buffer, pos, &ZSTR_LEN(*buffer), number, width, padding, alignment));
149+
PRINTF_DEBUG(("sprintf: appendint(%p, %zu, %zu, " ZEND_LONG_FMT ", %zu, '%c', %zu)\n",
150+
*buffer, *pos, ZSTR_LEN(*buffer), number, width, padding, alignment));
151151
if (number < 0) {
152152
neg = 1;
153153
magn = ((zend_ulong) -(number + 1)) + 1;
@@ -172,7 +172,7 @@ php_sprintf_appendint(zend_string **buffer, size_t *pos, zend_long number,
172172
} else if (always_sign) {
173173
numbuf[--i] = '+';
174174
}
175-
PRINTF_DEBUG(("sprintf: appending %d as \"%s\", i=%d\n",
175+
PRINTF_DEBUG(("sprintf: appending " ZEND_LONG_FMT " as \"%s\", i=%u\n",
176176
number, &numbuf[i], i));
177177
php_sprintf_appendstring(buffer, pos, &numbuf[i], width, 0,
178178
padding, alignment, (NUM_BUF_SIZE - 1) - i,
@@ -190,8 +190,8 @@ php_sprintf_appenduint(zend_string **buffer, size_t *pos,
190190
zend_ulong magn, nmagn;
191191
unsigned int i = NUM_BUF_SIZE - 1;
192192

193-
PRINTF_DEBUG(("sprintf: appenduint(%x, %x, %x, %d, %d, '%c', %d)\n",
194-
*buffer, pos, &ZSTR_LEN(*buffer), number, width, padding, alignment));
193+
PRINTF_DEBUG(("sprintf: appenduint(%p, %zu, %zu, " ZEND_LONG_FMT ", %zu, '%c', %zu)\n",
194+
*buffer, *pos, ZSTR_LEN(*buffer), number, width, padding, alignment));
195195
magn = (zend_ulong) number;
196196

197197
/* Can't right-pad 0's on integers */
@@ -206,7 +206,7 @@ php_sprintf_appenduint(zend_string **buffer, size_t *pos,
206206
magn = nmagn;
207207
} while (magn > 0 && i > 0);
208208

209-
PRINTF_DEBUG(("sprintf: appending %d as \"%s\", i=%d\n", number, &numbuf[i], i));
209+
PRINTF_DEBUG(("sprintf: appending " ZEND_LONG_FMT " as \"%s\", i=%d\n", number, &numbuf[i], i));
210210
php_sprintf_appendstring(buffer, pos, &numbuf[i], width, 0,
211211
padding, alignment, (NUM_BUF_SIZE - 1) - i, /* neg */ false, 0, 0);
212212
}
@@ -232,8 +232,8 @@ php_sprintf_appenddouble(zend_string **buffer, size_t *pos,
232232
struct lconv *lconv;
233233
#endif
234234

235-
PRINTF_DEBUG(("sprintf: appenddouble(%x, %x, %x, %f, %d, '%c', %d, %c)\n",
236-
*buffer, pos, &ZSTR_LEN(*buffer), number, width, padding, alignment, fmt));
235+
PRINTF_DEBUG(("sprintf: appenddouble(%p, %zu, %zu, %f, %zu, '%c', %zu, %c)\n",
236+
*buffer, *pos, ZSTR_LEN(*buffer), number, width, padding, alignment, fmt));
237237
if ((adjust & ADJ_PRECISION) == 0) {
238238
precision = FLOAT_PRECISION;
239239
} else if (precision > MAX_FLOAT_PRECISION) {
@@ -330,8 +330,8 @@ php_sprintf_append2n(zend_string **buffer, size_t *pos, zend_long number,
330330
zend_ulong i = NUM_BUF_SIZE - 1;
331331
int andbits = (1 << n) - 1;
332332

333-
PRINTF_DEBUG(("sprintf: append2n(%x, %x, %x, %d, %d, '%c', %d, %d, %x)\n",
334-
*buffer, pos, &ZSTR_LEN(*buffer), number, width, padding, alignment, n,
333+
PRINTF_DEBUG(("sprintf: append2n(%p, %zu, %zu, " ZEND_LONG_FMT ", %zu, '%c', %zu, %d, %p)\n",
334+
*buffer, *pos, ZSTR_LEN(*buffer), number, width, padding, alignment, n,
335335
chartable));
336336
PRINTF_DEBUG(("sprintf: append2n 2^%d andbits=%x\n", n, andbits));
337337

@@ -363,7 +363,7 @@ php_sprintf_getnumber(char **buffer, size_t *len)
363363
*len -= i;
364364
*buffer = endptr;
365365
}
366-
PRINTF_DEBUG(("sprintf_getnumber: number was %d bytes long\n", i));
366+
PRINTF_DEBUG(("sprintf_getnumber: number was %zu bytes long\n", i));
367367

368368
if (num >= INT_MAX || num < 0) {
369369
return -1;
@@ -431,6 +431,10 @@ php_formatted_print(char *format, size_t format_len, zval *args, int argc, int n
431431
int always_sign;
432432
int max_missing_argnum = -1;
433433

434+
/* For debugging */
435+
const char *format_orig = format;
436+
ZEND_IGNORE_VALUE(format_orig);
437+
434438
result = zend_string_alloc(size, 0);
435439

436440
currarg = 0;
@@ -464,8 +468,8 @@ php_formatted_print(char *format, size_t format_len, zval *args, int argc, int n
464468
always_sign = 0;
465469
expprec = 0;
466470

467-
PRINTF_DEBUG(("sprintf: first looking at '%c', inpos=%d\n",
468-
*format, format - Z_STRVAL_P(z_format)));
471+
PRINTF_DEBUG(("sprintf: first looking at '%c', inpos=%zu\n",
472+
*format, format - format_orig));
469473
if (isalpha((int)*format)) {
470474
width = precision = 0;
471475
argnum = ARG_NUM_NEXT;
@@ -478,8 +482,8 @@ php_formatted_print(char *format, size_t format_len, zval *args, int argc, int n
478482

479483
/* after argnum comes modifiers */
480484
PRINTF_DEBUG(("sprintf: looking for modifiers\n"
481-
"sprintf: now looking at '%c', inpos=%d\n",
482-
*format, format - Z_STRVAL_P(z_format)));
485+
"sprintf: now looking at '%c', inpos=%zu\n",
486+
*format, format - format_orig));
483487
for (;; format++, format_len--) {
484488
if (*format == ' ' || *format == '0') {
485489
padding = *format;

0 commit comments

Comments
 (0)