mirror of
https://github.com/systemd/systemd-stable.git
synced 2025-01-08 21:17:47 +03:00
util: add check that makes sure time_t and TIME_T_MAX work the way we assume they do
This commit is contained in:
parent
59e73c5b10
commit
2d60169dd6
@ -69,7 +69,7 @@ typedef struct dual_timestamp {
|
|||||||
#define FORMAT_TIMESTAMP_RELATIVE_MAX 256
|
#define FORMAT_TIMESTAMP_RELATIVE_MAX 256
|
||||||
#define FORMAT_TIMESPAN_MAX 64
|
#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 })
|
#define DUAL_TIMESTAMP_NULL ((struct dual_timestamp) { 0ULL, 0ULL })
|
||||||
|
|
||||||
|
@ -192,6 +192,8 @@ static void test_usec_add(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
|
uintmax_t x;
|
||||||
|
|
||||||
test_parse_sec();
|
test_parse_sec();
|
||||||
test_parse_time();
|
test_parse_time();
|
||||||
test_parse_nsec();
|
test_parse_nsec();
|
||||||
@ -202,5 +204,13 @@ int main(int argc, char *argv[]) {
|
|||||||
test_get_timezones();
|
test_get_timezones();
|
||||||
test_usec_add();
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user