3 ms·
No, the problem is using the wrong data type: "long". On 32-bit systems, Linux defines long to be 32-bits,vs 64 bits on 64-bit. As another example of how this c
by hermitdev 4y ago
No, the problem is using the wrong data type: "long". On 32-bit systems, Linux defines long to be 32-bits,vs 64 bits on 64-bit. As another example of how this could be broken: use this code on Windows, either 32 or 64 bit and the code is completely broken because longs are 32-bits regardless of whether the OS is 32 or 64 bit capable. Use time_t as that's the correct type and will do the right thing assuming your C standard lib is up to date.
- nebulous1 4y agoWell, the problem is that it is casting (t + DAY/2) to a long before it divides by DAY, not after. The whole expression ((t + DAY/2) / DAY) will not overflow 32 bits in any reasonable timeframe, but (t + DAY / 2) will.
- Arnavion 4y agohttps://github.com/shadow-maint/shadow/commit/815ffb7d3e0a8e1d78886dded65a5c6afd22c94e#diff-9ade509d0a1eeb8cd0b2638ddf8ddb2bd65a8dd3a901c829fcac29c12cd42588R81 https://github.com/shadow-maint/shadow/commit/815ffb7d3e0a8e... Amusing that it was broken by an attempt to make it clearer.