PSPP - Patches: patch #5727, fix size_t format specifiers
You are not allowed to post comments on this tracker with your current authentication level.
patch #5727: fix size_t format specifiers
Submitter: | Ben Pfaff <blp> | ||
Submitted: | Wed 07 Feb 2007 05:24:45 AM UTC | ||
Category: | None | Item Group: | None |
Status: | Done | Assigned to: | None |
Open/Closed: | Closed |
Thu 08 Feb 2007 05:54:48 AM UTC, comment #3: |
Ben Pfaff <blp> |
Wed 07 Feb 2007 11:20:41 PM UTC, comment #2: I'm not sure what this will actually do for us.
|
John Darrington <jmd> |
Wed 07 Feb 2007 01:46:56 PM UTC, comment #1: Works for me on OBSD, 64-bit x86.
|
Jason H Stover <jstover> |
Wed 07 Feb 2007 05:24:45 AM UTC, original submission:
We weren't always formatting "size_t"s correctly (by casting them to another type and using the appropriate format). This is sure to be a problem on 64-bit machines. Here's a patch. |
Ben Pfaff <blp> |
Depends on the following items: None found
Items that depend on this one: None found
There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.
Follow 3 latest changes.
Date | Changed by | Updated Field | Previous Value | => | Replaced by |
---|---|---|---|---|---|
2007-02-09 | blp | Status | Ready For Test/Review | Done | |
Open/Closed | Open | Closed | |||
2007-02-07 | blp | Attached File | - | Added printf.patch, #11938 |
Powered by Savane 3.13-d3ae.
Corresponding source code
The implementation of printf has little to do with it. The compiler passes arguments to printf as the types that are supplied. It doesn't know what format specifier(s) are given. Thus, if you pass a 64-bit size_t for a %d argument, and on that machine "int" is 32 bits, then what you print is half garbage.
Now, GCC is a little smarter and knows about printf, but that doesn't change how it passes arguments, it just allows it to print out helpful warnings.
The changes I made all have the effect of making the argument match the format specifier: if I cast to int, then I use %d; if I cast to unsigned long, then I use %lu; and so on. Arguably I could have chosen different types in some cases, but I tried to choose what made sense to me at the time.
I'm hoping that someday gnulib will replace printf-like functions with versions that accept the "z" format specifier (which was introduced in C99 for printing size_t), so that instead of these casts we can just write "%zu". But that day is not here yet.