]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
util: add check that makes sure time_t and TIME_T_MAX work the way we assume they do
authorLennart Poettering <lennart@poettering.net>
Wed, 3 Feb 2016 20:05:59 +0000 (21:05 +0100)
committerLennart Poettering <lennart@poettering.net>
Wed, 3 Feb 2016 22:58:25 +0000 (23:58 +0100)
src/basic/time-util.h
src/test/test-time.c

index b37d5ad5dc5721dcdd6b71b2b648cb36c9d0182a..9c7758a9596802a423994618b0644d7e056481f7 100644 (file)
@@ -69,7 +69,7 @@ typedef struct dual_timestamp {
 #define FORMAT_TIMESTAMP_RELATIVE_MAX 256
 #define FORMAT_TIMESPAN_MAX 64
 
-#define TIME_T_MAX (time_t)((1UL << ((sizeof(time_t) << 3) - 1)) - 1)
+#define TIME_T_MAX (time_t)((UINTMAX_C(1) << ((sizeof(time_t) << 3) - 1)) - 1)
 
 #define DUAL_TIMESTAMP_NULL ((struct dual_timestamp) { 0ULL, 0ULL })
 
index ca44f81f9c5b55b307c3c32d2ab0b12c38a115f9..254a8d0e529eec9ca4871552eb2b95c1d4ed17c7 100644 (file)
@@ -192,6 +192,8 @@ static void test_usec_add(void) {
 }
 
 int main(int argc, char *argv[]) {
+        uintmax_t x;
+
         test_parse_sec();
         test_parse_time();
         test_parse_nsec();
@@ -202,5 +204,13 @@ int main(int argc, char *argv[]) {
         test_get_timezones();
         test_usec_add();
 
+        /* Ensure time_t is signed */
+        assert_cc((time_t) -1 < (time_t) 1);
+
+        /* Ensure TIME_T_MAX works correctly */
+        x = (uintmax_t) TIME_T_MAX;
+        x ++;
+        assert((time_t) x < 0);
+
         return 0;
 }