[Toybox] Stat %Z - What are valid values?

enh enh at google.com
Fri Dec 30 13:57:19 PST 2016


On Fri, Dec 30, 2016 at 1:44 PM, Rob Landley <rob at landley.net> wrote:
> I have negotiated a 3 day weekend for the holidays! Starting today. Ok,
> catching up...
>
> On 12/30/2016 01:39 PM, enh wrote:
>> time_t on 32-bit Android is 32 bits.
>>
>> that particular value looks like a sign-extension of 0xAFBEADCE, which
>> is still some time in 2063.
>
> Or if it's signed, that's -1346458162 which would be... sometime in the
> 1930's? hmmm... "./date -D %s -d -1346458162" is failing under glibc,
> and failing _differently_ under musl. (Wheee.)
>
> /me goes down tangent rathole debugging why. (THIS is why I need to
> finish mkroot and get a toybox test environment set up that can test
> stuff requiring root access under qemu under a known root filesystem and
> kernel config. Is my code broken, or does strptime not parse negative
> numerical arguments for %s format?)
>
> (Answer: musl doesn't implement %s at all, and glibc doesn't allow the
> %s value it converts to be negative. And of course posix doesn't specify
> signed OR unsigned for time_t at
> http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_types.h.html
> because actually providing enough detail to implement things would be
> _useful_.)
>
>> two patches attached. one avoids sign extension for all calls to
>> `out`, fixing %Z for systems with a signed 32-bit time_t.
>
> The 0001-Avoid* patch only has the first hunk, which defines two macros
> there are never used and renames a function but not its users.

one of the macros takes the old name of the function. because to do
what you _wanted_ the function to do (hide all the casting nonsense)
it either has to be a template (but this is just C) or a macro.

i did consider calling the function __out rather than uout ("unsigned
out") to make this more obvious, but uout seemed more toybox style.

so, anyway, all the callers now call the `out` macro, which uses the
`add_unsigned` macro to add `unsigned` to whatever the type the
argument already has, then passes it to `uout` which is just the
unsigned version of the old `out`. because it's now an
unsigned-to-unsigned promotion, there's no sign extension, so you get
the right answer for a `time_t` in cases where `time_t` is `int32_t`.

>>> This seems suspiciously large and I'm wondering what the valid range for
>>> this value is.
>
> I think we all do at this point.
>
> Rob



-- 
Elliott Hughes - http://who/enh - http://jessies.org/~enh/
Android native code/tools questions? Mail me/drop by/add me as a reviewer.


More information about the Toybox mailing list