Opened 14 years ago
Closed 12 years ago
#2024 closed Bugs (wontfix)
boost::format("%p") % (uint8_t *) str is not like printf("%p", str)
Reported by: | Owned by: | Samuel Krempp | |
---|---|---|---|
Milestone: | To Be Determined | Component: | format |
Version: | Boost 1.34.0 | Severity: | Problem |
Keywords: | Cc: |
Description
I'm actually on 1.33.1 still but I can't see any difference that fixes this in the latest code.
The boost::format gets pointers to 8-bit types wrong. This because the underlying type is indistinguishable from a string. In this case, I think the formatting needs to take the hint from the format string about how to interpret the type.
I have a fix which is slightly hacky. Instead of passing the printf parameter directly to %, it can be wrapped in a container whose insertion method inspects the stream flags to see whether any of the basefield bits are set and only prints like a char/string if none of them are. The wrapper type is in the attachment. The format parsing needs to clear the basefield bits. Here is the diff from format/parsing.hpp:
321d320 < fpar->fmtstate_.flags_ &= ~std::ios_base::basefield; 326d324 < fpar->fmtstate_.flags_ &= ~std::ios_base::basefield;
Attachments (1)
Change History (3)
by , 14 years ago
Attachment: | format_printf.cc added |
---|
comment:1 by , 13 years ago
comment:2 by , 12 years ago
Resolution: | → wontfix |
---|---|
Status: | new → closed |
My copy of the C99 standard (n869) says about "%p":
p The argument shall be a pointer to void. The value of the pointer is converted to a sequence of printing characters, in an implementation-defined manner.
Given that, I don't see any way that Boost.Format can "match what printf prints".
This still a problem in 1.42:
prints two different lines.