X-Git-Url: http://git.csclub.uwaterloo.ca/?p=kopensolaris-gnu%2Fglibc.git;a=blobdiff_plain;f=time%2Ftzfile.c;h=e78a05ec75432c6f70dcfa8ac3f302c873349108;hp=9ff24df08b847bbbc15b2da990b7c9f7746d898b;hb=0a0d9d20f716a8b48e2a2d2c6c243997d8b15543;hpb=94c6737f3a0bd1f22e4275863d489e8b7b7ad1e1 diff --git a/time/tzfile.c b/time/tzfile.c index 9ff24df08b..e78a05ec75 100644 --- a/time/tzfile.c +++ b/time/tzfile.c @@ -60,19 +60,20 @@ static struct leap *leaps = NULL; static inline int decode (const void *ptr) { -#if BYTE_ORDER == BIG_ENDIAN - return *(const int *) ptr; -#else - const unsigned char *p = ptr; - int result = 0; - - result = (result << 8) | *p++; - result = (result << 8) | *p++; - result = (result << 8) | *p++; - result = (result << 8) | *p++; - - return result; -#endif + if ((BYTE_ORDER == BIG_ENDIAN) && sizeof (int) == 4) + return *(const int *) ptr; + else + { + const unsigned char *p = ptr; + int result = *p & (1 << (CHAR_BIT - 1)) ? ~0 : 0; + + result = (result << 8) | *p++; + result = (result << 8) | *p++; + result = (result << 8) | *p++; + result = (result << 8) | *p++; + + return result; + } } void @@ -158,6 +159,9 @@ DEFUN(__tzfile_read, (file), CONST char *file) goto lose; } + if (sizeof (time_t) < 4) + abort (); + if (fread((PTR) transitions, 4, num_transitions, f) != num_transitions || fread((PTR) type_idxs, 1, num_transitions, f) != num_transitions) goto lose; @@ -169,7 +173,7 @@ DEFUN(__tzfile_read, (file), CONST char *file) the array so as not to clobber the next element to be processed when sizeof (time_t) > 4. */ i = num_transitions; - while (num_transitions-- > 0) + while (i-- > 0) transitions[i] = decode ((char *) transitions + i*4); } @@ -269,7 +273,7 @@ DEFUN(__tzfile_default, (std, dst, stdoff, dstoff), /* Find the standard and daylight time offsets used by the rule file. We choose the offsets in the types of each flavor that are transitioned to earliest in time. */ - rule_dstoff = 0; + rule_stdoff = rule_dstoff = 0; for (i = 0; i < num_transitions; ++i) { if (!rule_stdoff && !types[type_idxs[i]].isdst)