chiark / gitweb /
Simplify execute_directory()
[elogind.git] / src / shared / time-dst.c
index 65e2998c983a5f9bab9343b1b5cfe15c58b03a05..1ce6f721b7c895a5260d5b01b4faa92905d6f501 100644 (file)
@@ -183,7 +183,8 @@ read_again:
                         return -EINVAL;
         }
 
-        transitions = malloc0(total_size + tzspec_len);
+        /* leave space for additional zone_names zero terminator */
+        transitions = malloc0(total_size + tzspec_len + 1);
         if (transitions == NULL)
                 return -EINVAL;
 
@@ -207,8 +208,8 @@ read_again:
                 if (type_idxs[i] >= num_types)
                         return -EINVAL;
 
-        if ((BYTE_ORDER != BIG_ENDIAN && (sizeof(time_t) == 4 || trans_width == 4)) ||
-            (BYTE_ORDER == BIG_ENDIAN && sizeof(time_t) == 8 && trans_width == 4)) {
+        if (__BYTE_ORDER == __BIG_ENDIAN ? sizeof(time_t) == 8 && trans_width == 4
+                                         : sizeof(time_t) == 4 || trans_width == 4) {
                 /* Decode the transition times, stored as 4-byte integers in
                    network (big-endian) byte order.  We work from the end of
                    the array so as not to clobber the next element to be
@@ -216,7 +217,7 @@ read_again:
                 i = num_transitions;
                 while (i-- > 0)
                         transitions[i] = decode((char *)transitions + i * 4);
-        } else if (BYTE_ORDER != BIG_ENDIAN && sizeof(time_t) == 8) {
+        } else if (__BYTE_ORDER != __BIG_ENDIAN && sizeof(time_t) == 8) {
                 /* Decode the transition times, stored as 8-byte integers in
                    network (big-endian) byte order.  */
                 for (i = 0; i < num_transitions; ++i)
@@ -244,6 +245,8 @@ read_again:
         if (fread(zone_names, 1, chars, f) != chars)
                 return -EINVAL;
 
+        zone_names[chars] = '\0';
+
         for (i = 0; i < num_isstd; ++i) {
                 int c = getc(f);
                 if (c == EOF)