[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Dealing with uninitialized padding in `struct timespec` with 32bit Linux
|
From: |
Carlo Arenas |
|
Subject: |
Dealing with uninitialized padding in `struct timespec` with 32bit Linux using 64bit time_t |
|
Date: |
Sun, 14 May 2023 17:46:35 -0700 |
At least gcc-13 triggers -Wanalyzer-use-of-uninitialized-value for
code like (compile with -D_TIME_BITS=64 if using glibc; requires glibc
>= 2.34) :
struct timespec f(void)
{
struct timespec t;
t.tv_sec = 0;
t.tv_nsec = 0;
return t;
}
Which seems to be common, and that could be silenced by initializing
the variable first (ex: t = {0}).
The 4 byte padding will be added either before or after tv_nsec,
depending on endianness, and is IMHO harmless even if uninitialized,
but it is not a false positive, so not sure if suppressing it might be
worth considering.
Either way, worth addressing, and if so, which way?
Carlo
- Dealing with uninitialized padding in `struct timespec` with 32bit Linux using 64bit time_t,
Carlo Arenas <=