diff options
author | Zack Weinberg <zackw@panix.com> | 2019-08-19 13:51:25 -0400 |
---|---|---|
committer | Zack Weinberg <zackw@panix.com> | 2019-08-28 09:02:34 -0400 |
commit | c50ec7ce062883cbb3d1820b2c1ea262ca5fff5b (patch) | |
tree | 653bdf5d0e6ecd10f74c7b2da8748b1163724ea7 /math/test-float-finite.c | |
parent | 10a105817921d6de8e7f5a68704168d5a8abf6d2 (diff) | |
download | glibc-c50ec7ce062883cbb3d1820b2c1ea262ca5fff5b.tar.gz |
Warn when gettimeofday is called with non-null tzp argument.
Since there are no known uses of gettimeofday's vestigial "get time
zone" feature that are not bugs, add a fortify-style wrapper inline to
sys/time.h that issues a warning whenever gettimeofday is called with
a second argument that is not a compile-time null pointer
constant.
At present this is only possible with GCC; clang does not implement
attribute((warning)). The wrapper is only activated when __OPTIMIZE__
is defined because it throws false positives when optimization is off,
even though it's an always-inline function.
An oversight in the implementation of __builtin_constant_p causes it
to fail to detect compile-time *pointer* constants unless they are
cast to an integer of a different size. (Loss of data in this cast is
harmless; the overall expression is still constant if and only if the
original pointer was.) This is GCC bug 95514. Thanks to
Kamil Cukrowski <kamilcukrowski@gmail.com> for the workaround.
As a precaution, I added a static assertion to debug/warning-nop.c to
make sure that the cast _is_ casting to an integer of a different
size; this is too unlikely a scenario to be worth checking in the
public header, but if someone ever adds a port where short is the
same size as intptr_t, we'll still catch it.
Also make the public prototype of gettimeofday declare its second
argument with type "void *" unconditionally, consistent with POSIX.
* time/sys/time.h (__timezone_ptr_t): Delete.
(gettimeofday): Always declare second argument with type "void *".
When possible, wrap with a fortify-style inline function that
detects non-null or non-constant second argument and issues a
warning. Improve commentary.
(settimeofday): Improve commentary.
* time/gettimeofday.c (gettimeofday): Declare second argument with
type "void *".
* debug/warning-nop.c: Include sys/time.h and stdint.h.
Add static_assert to verify the requirements of the workaround
for GCC bug 95514.
Diffstat (limited to 'math/test-float-finite.c')
0 files changed, 0 insertions, 0 deletions