Coding standards for 32/64-bits data
OBATA Akio
obata at lins.jp
Fri Jul 1 04:05:41 EDT 2011
On Fri, 01 Jul 2011 14:57:01 +0900, Bron Gondwana <brong at fastmail.fm> wrote:
> On Fri, Jul 01, 2011 at 10:46:05AM +0900, OBATA Akio wrote:
>> I want to clear following issue before NetBSD-6.0 release.
>> http://gnats.netbsd.org/44275
>>
>> Then, workaround until 32-bits time_t overflow is "cast to `unsigned long'"
>> time_t data to pass snprintf with "%lu" format?
>>
>> I can find it in imap/mailbox.c and imap/sync_client.c.
>> (other issues are not discovered for me at the moment).
>
> I'm happy for you to do that.
>
> brong at launde:/extra/src/git/cmu/cyrus-imapd$ ack time_t | wc -l
> 276
>
> It looks like there's a maximum of 300 places that times are
> defined.
>
> Should we cast them to (unsigned long long) and then print them
> with %llu? That way we're 64 bit safe in a few more places!
I feel that almost of them are using as time_t, and system library functions
only accept time_t type (and performance matter), so may of them should be kept as is.
For printf format, how about to detect it in configure script?
if (sizeof(time_t) == sizeof(unsigned long long))
#define TIME_T_FMT "%llu"
else
#define TIME_T_FMT "%lu"
I saw some bare binary time_t data input/output, and it will wreak some database incompatibility
at converting to different time_t size and/or endian platform, but it is different issue.
--
OBATA Akio / obata at lins.jp
More information about the Cyrus-devel
mailing list