1 Feb 2005 07:03
snprintf defects [Was: Wrong endptr in strtold()]
On 2005-01-31 17:01 PM, Egon Andersen wrote:
>
> Just for the fun, try to snprintf a double with 2 decimals e.g. ".2f"
> and let the value be infinity.
> I get as result something like "1.#J"
> I think it is time to make a proper implementation of snprintf() not
> based on M$
Other snprintf problems:
char buf[100] = "zzzzzzzzz";
std::cout << snprintf(buf, 0, "%4d", 1234) << '\n'; // Should equal 4.
std::cout << snprintf(buf, 3, "%4d", 1234) << '\n'; // Should equal 4.
std::cout << std::string(buf, 9) << '\n'; // Should be "12\0zzzzzz\0".
snprintf(buf, 4, "%4d", 1234);
std::cout << std::string(buf, 9) << '\n'; // Should be "123\0zzzzz\0".
With the latest release, I get
-1
-1
123zzzzzz
1234zzzzz
I think it's always been that way.
MinGW's sprintf() calls _vsnprintf(), which is known to be defective:
http://www.gotw.ca/publications/mill19.htm
"In particular, under one major implementation, if the output fills
or would overflow the buffer then the buffer is not zero-terminated."
(Continue reading)
But since I have no access to Linux right now, it raises the whole
desire for portable tools and applications. So if I write code in
Windows, I'd like to be able to port it to Linux in the future with
minimal difficulty. I have no doubt of it's usefulness once I get
everything the way I want it.
Well, it's a natural tendency to gripe. :p I hope I wasn't too bad at
it. I'm not just dropping an inflamatory comment and running away. I'd
like to help, but practical contributions will be limited to text-only,
non-network stuff, like scripts to parse data and HTML output, or using
a network library or external program so I fetch data from a URL, and no
GUI stuff (unless I strike extreme enlightment in a short time). As I
have no idea how the data is actually retrieved or what script parses
and formats that data for presentation, I used JavaScript as a
concept-modelling language and have worked out some logic to streamline
to entire look of the table.
1) Flat table, with rowspans, no nested tables.
2) border=1, cellpadding=1, cellspacing=0
3) combined date and time to 2005-02-01 <at> 06:50 format, 2->1 columns.
4) Page size from 88 kb to 58 kb.
RSS Feed