mirror of
https://github.com/coreutils/coreutils.git
synced 2024-11-27 12:04:25 +08:00
build: prohibit improper use of stat and lstat
* cfg.mk (sc_prohibit_stat_macro_address): New rule. * src/ln.c (do_link): Adjust comment to avoid false positive. * src/stat.c (do_stat): Likewise. * src/touch.c (main): Likewise.
This commit is contained in:
parent
a08e13a0fb
commit
c0dcf3238b
6
cfg.mk
6
cfg.mk
@ -197,6 +197,12 @@ sc_prohibit_readlink:
|
||||
msg='do not use readlink(at); use via xreadlink or areadlink*' \
|
||||
$(_prohibit_regexp)
|
||||
|
||||
# Don't use address of "stat" or "lstat" functions
|
||||
sc_prohibit_stat_macro_address:
|
||||
@re='\<l?stat '':|&l?stat\>' \
|
||||
msg='stat() and lstat() may be function-like macros' \
|
||||
$(_prohibit_regexp)
|
||||
|
||||
# Ensure that date's --help output stays in sync with the info
|
||||
# documentation for GNU strftime. The only exception is %N,
|
||||
# which date accepts but GNU strftime does not.
|
||||
|
2
src/ln.c
2
src/ln.c
@ -138,7 +138,7 @@ do_link (const char *source, const char *dest)
|
||||
{
|
||||
/* Which stat to use depends on whether linkat will follow the
|
||||
symlink. We can't use the shorter
|
||||
(logical ? stat : lstat) (source, &source_stats)
|
||||
(logical?stat:lstat) (source, &source_stats)
|
||||
since stat might be a function-like macro. */
|
||||
if ((logical ? stat (source, &source_stats)
|
||||
: lstat (source, &source_stats))
|
||||
|
@ -903,7 +903,7 @@ do_stat (char const *filename, bool terse, char const *format)
|
||||
}
|
||||
}
|
||||
/* We can't use the shorter
|
||||
(follow_links ? stat : lstat) (filename, &statbug)
|
||||
(follow_links?stat:lstat) (filename, &statbug)
|
||||
since stat might be a function-like macro. */
|
||||
else if ((follow_links
|
||||
? stat (filename, &statbuf)
|
||||
|
@ -348,7 +348,7 @@ main (int argc, char **argv)
|
||||
if (use_ref)
|
||||
{
|
||||
struct stat ref_stats;
|
||||
/* Don't use (no_dereference ? lstat : stat) (args), since stat
|
||||
/* Don't use (no_dereference?lstat:stat) (args), since stat
|
||||
might be an object-like macro. */
|
||||
if (no_dereference ? lstat (ref_file, &ref_stats)
|
||||
: stat (ref_file, &ref_stats))
|
||||
|
Loading…
Reference in New Issue
Block a user