[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] timespec: fill in other members
From: |
Pádraig Brady |
Subject: |
Re: [PATCH] timespec: fill in other members |
Date: |
Mon, 15 May 2023 12:50:05 +0100 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Thunderbird/109.0 |
On 15/05/2023 07:30, Paul Eggert wrote:
This problem was found when compiling GNU Emacs with
--enable-gcc-warnings on a platform where tv_sec is 64 bits and
tv_nsec is 32 bits, and struct timespec has padding. GCC
-Wuse-of-uninitialized-value complained when a struct timespec
initialized only via assigning to tv_sec and tv_nsec was copied
via assignment (this was in lib/timespec.h’s make_timespec).
Although behavior is well-defined on this platform, the warning is
annoying and the behavior might not be well-defined on theoretical
platforms where struct timespec has other members. To work around
this, initialize all the struct’s members.
* lib/utimecmp.c (utimecmpat):
* lib/utimens.c (fdutimens):
When filling in a struct timespec or similar time-related structure
that might be copied elsewhere, also assign to any storage other
than tv_sec and tv_nsec, to avoid undefined behavior on (likely
theoretical) platforms where struct timespec has other members,
and also to avoid warnings from GCC and/or valgrind.
The new coreutils CI I have in place is failing to build
with gcc (Debian 10.2.1-6) 10.2.1 with gnulib latest (ebd843b3) as follows.
I think this may be due to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82283
It's a pity that doesn't seem to have been backported to gcc 10 (2020).
I was thinking I might need to ./configure --enable-gcc-warnings=no for CI
at some stage, but it seems that's sooner rather than later.
It might be worth reverting the change to lib/utimecmp.c
and perhaps instead initializing with `= {0}`.
I confirmed that builds without issue.
cheers,
Pádraig
lib/utimecmp.c: In function 'utimecmpat':
lib/utimecmp.c:348:17: error: missing initializer for field 'tv_nsec' of
'struct timespec' [-Werror=missing-field-initializers]
348 | [0].tv_nsec = dst_a_ns,
| ^
In file included from /usr/include/x86_64-linux-gnu/sys/select.h:39,
from ./lib/sys/select.h:114,
from /usr/include/x86_64-linux-gnu/sys/types.h:179,
from ./lib/sys/types.h:46,
from lib/utimecmp.h:23,
from lib/utimecmp.c:22:
/usr/include/x86_64-linux-gnu/bits/types/struct_timespec.h:16:21: note:
'tv_nsec' declared here
16 | __syscall_slong_t tv_nsec; /* Nanoseconds. */
| ^~~~~~~
lib/utimecmp.c:350:17: error: missing initializer for field 'tv_nsec' of
'struct timespec' [-Werror=missing-field-initializers]
350 | [1].tv_nsec = dst_m_ns + res / 9
| ^
In file included from /usr/include/x86_64-linux-gnu/sys/select.h:39,
from ./lib/sys/select.h:114,
from /usr/include/x86_64-linux-gnu/sys/types.h:179,
from ./lib/sys/types.h:46,
from lib/utimecmp.h:23,
from lib/utimecmp.c:22:
/usr/include/x86_64-linux-gnu/bits/types/struct_timespec.h:16:21: note:
'tv_nsec' declared here
16 | __syscall_slong_t tv_nsec; /* Nanoseconds. */
| ^~~~~~~