Bug 56120 - Add support for 'z' (size_t) to snprintf
Summary: Add support for 'z' (size_t) to snprintf
Status: NEW
Alias: None
Product: APR
Classification: Unclassified
Component: APR (show other bugs)
Version: HEAD
Hardware: All All
: P2 enhancement (vote)
Target Milestone: ---
Assignee: Apache Portable Runtime bugs mailinglist
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-02-07 21:07 UTC by Andy Harrison
Modified: 2014-04-13 20:41 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andy Harrison 2014-02-07 21:07:57 UTC
I noticed this while trying to use %{mod_php_memory_usage} in a LogFormat directive. The PHP source (sapi_apache2.c) calls apr_psprintf using a %zu format. Instead of expanding, %zu is written in plain text to the log file.

Doesn't look like many other people have stumbled on this issue, I only turned up one with this specific problem:

http://stackoverflow.com/questions/21549852/apache-mod-php-memory-usage-prints-zu-instead-of-useful-data

I looked at the glibc source, but %z has existed there for 10+ years.  So I went looking at the php source. Here is the php commit from May 16, 2011 that implemented the %zu, but the comment isn't terribly descriptive:  

https://github.com/php/php-src/commit/e0df4e3dba7c4ab92442b9e82c1de01fdbaa3cce

I see that you've implemented other characters to expand over time, so I thought this would be a good one to add to the list.
Comment 1 Jeff Trawick 2014-04-13 20:41:33 UTC
The z prefix is standard with C99, so it would be nice for APR to support that in a future release (i.e., starting with APR 1.6 or 2.0).

PHP should be using APR_SIZE_T_FMT, as in the following call:

apr_psprintf(ctx->r->pool, "%" APR_SIZE_T_FMT, zend_memory_peak_usage(1 TSRMLS_CC)));

I posted that to the PHP folks via https://github.com/php/php-src/pull/641.

We'll leave this APR issue open as an enhancement request.