Systemd/coccinelle
Frantisek Sumsal 17e3e37c05 coccinelle: avoid matching 'errno' as a file descriptor
The `coccinelle/take-fd.cocci` transformation file attempts to rewrite

r = fd;
fd = -1;

to

r = TAKE_FD(fd);

Unfortunately, using `identifier` or `idexpression` as a metavariable
type in this case wouldn't match more complex location descriptions,
like:

x->fd = fd
fd = -1;

Using 'expression' metavariable type generates false positives,
as you can't specify scope of such expression. The only real example
from the current codebase is the global 'errno' variable, which results
in following patch generated by `spatch`:

--- src/basic/errno-util.h
+++ /tmp/cocci-output-28263-971baa-errno-util.h
@@ -15,8 +15,7 @@ static inline void _reset_errno_(int *sa

 #define UNPROTECT_ERRNO                         \
         do {                                    \
-                errno = _saved_errno_;          \
-                _saved_errno_ = -1;             \
+                errno = TAKE_FD(_saved_errno_);             \
         } while (false)

 static inline int negative_errno(void) {

Let's explicitly state that the matched expression should not equal
'errno' to avoid this. It's not particularly nice, but it should be
enough, at least for now.
2019-04-27 15:46:48 +02:00
..
bool-cast.cocci tree-wide: drop !! casts to booleans 2018-06-13 10:52:40 +02:00
close-above-stdio.cocci util: add new safe_close_above_stdio() wrapper 2018-02-28 10:00:50 +01:00
cmp.cocci tree-wide: CMP()ify all the things 2018-10-16 17:45:53 +02:00
const-strlen.cocci tree-wide: make use of new STRLEN() macro everywhere (#7639) 2017-12-14 19:02:29 +01:00
debug-logging.cocci tree-wide: add DEBUG_LOGGING macro that checks whether debug logging is on (#7645) 2017-12-15 11:09:00 +01:00
div-round-up.cocci coccinelle: make use of DIV_ROUND_UP() wherever appropriate 2018-03-20 20:59:02 +01:00
dup-fcntl.cocci coccinelle: always use fcntl(fd, FD_DUPFD, 3) instead of dup(fd) 2018-03-20 22:31:14 +01:00
empty-or-dash.cocci coccinelle: add coccinelle script for empty_or_dash() use 2019-04-08 14:31:15 +02:00
empty-or-root.cocci util-lib: introduce new empty_or_root() helper (#8746) 2018-04-18 14:20:49 +02:00
empty-to-null.cocci core: use empty_to_null() where we can 2017-12-07 12:13:00 +01:00
enotsup.cocci cocci: there's not ENOTSUP, there's only EOPNOTSUPP 2018-01-11 15:12:16 +01:00
equals-null.cocci tree-wide: drop a few == NULL and != NULL comparison 2017-12-11 16:05:40 +01:00
errno.cocci coccinelle: additional errno.cocci hunk 2015-11-09 20:01:06 +01:00
exit-0.cocci tree-wide: use EXIT_SUCCESS/EXIT_FAILURE in exit() where we can 2017-12-25 11:48:21 +01:00
flags-set.cocci Add macro for checking if some flags are set 2018-06-04 11:50:44 +02:00
fopen-unlocked.cocci Add open_memstream_unlocked() wrapper 2019-04-12 11:44:57 +02:00
free_and_replace.cocci tree-wide: introduce free_and_replace helper 2016-10-16 23:35:39 -04:00
hashmap_free.cocci tree-wide: take benefit of the fact that hashmap_free() returns NULL 2015-09-09 23:12:07 +02:00
htonl.cocci tree-wide: htonl() is weird, let's use htobe32() instead (#3538) 2016-06-15 01:26:01 +02:00
in_set.cocci coccinelle: fix IN_SET/!IN_SET scripts, and apply some changes it found 2017-11-29 20:12:26 +01:00
iovec-make.cocci tree-wide: more IOVEC_MAKE() conversions 2018-11-28 13:08:19 +09:00
isempty.cocci coccinelle: beef up isempty() checks (#7729) 2017-12-23 08:47:55 +01:00
log-json.cocci nspawn-oci: use SYNTHETIC_ERRNO 2019-03-21 10:51:43 +01:00
malloc_multiply.cocci coccinelle: similar to reallocarray() let's also systematically use malloc_multiply() 2018-03-02 12:39:07 +01:00
memzero.cocci coccinelle: automatically rewrite memset() to zero() or memzero() where we can 2017-12-14 19:47:46 +01:00
mfree.cocci tree-wide: use coccinelle to patch a lot of code to use mfree() 2015-09-09 08:19:27 +02:00
mfree_return.cocci tree-wide: use mfree more 2016-10-16 23:35:39 -04:00
no-if-assignments.cocci tree-wide: don't do assignments within if checks 2015-09-09 08:20:20 +02:00
not_in_set.cocci coccinelle: fix IN_SET/!IN_SET scripts, and apply some changes it found 2017-11-29 20:12:26 +01:00
o-ndelay.cocci coccinelle: fix typo in file name (#8640) 2018-04-02 23:30:26 +09:00
reallocarray.cocci coccinelle: add reallocarray() coccinelle script 2018-03-02 12:39:07 +01:00
redundant-if.cocci cocci: simplify some if checks 2018-11-16 16:05:29 +01:00
run-coccinelle.sh coccinelle: add explicit statement isomorphisms 2019-04-27 15:26:11 +02:00
safe_close-no-if.cocci tree-wide: drop redundant if checks before safe_close() 2015-09-09 08:20:19 +02:00
safe_close.cocci tree-wide: make more code use safe_close() 2015-09-09 08:20:19 +02:00
safe_closedir.cocci util: add safe_closedir() similar to safe_fclose() 2015-09-22 16:30:24 +02:00
safe_fclose.cocci util: introduce safe_fclose() and port everything over to it 2015-09-09 15:26:11 +02:00
strempty.cocci cocci: use strempty() at more places 2018-01-10 17:11:19 +01:00
strjoin.cocci tree-wide: drop NULL sentinel from strjoin 2016-10-23 11:43:27 -04:00
strjoina.cocci tree-wide: remove useless NULLs from strjoina 2016-04-13 08:56:44 -04:00
strv_free.cocci tree-wide: make use of the fact that strv_free() returns NULL 2015-09-09 23:05:58 +02:00
swap-two.cocci tree-wide: use SWAP_TWO a bit more 2018-11-26 22:17:34 +01:00
synthetic-errno.cocci coccinelle: also mark previous synthetic errnos as such 2018-11-22 10:54:38 +01:00
systemd-definitions.iso coccinelle: add explicit statement isomorphisms 2019-04-27 15:26:11 +02:00
take-fd.cocci coccinelle: avoid matching 'errno' as a file descriptor 2019-04-27 15:46:48 +02:00
take-ptr.cocci macro: introduce TAKE_PTR() macro 2018-03-22 20:21:42 +01:00
while-true.cocci tree-wide: replace while(1) by for(;;) everywhere 2015-09-09 14:59:53 +02:00
xsprintf.cocci tree-wide: use xsprintf() where applicable 2016-01-12 15:36:32 +01:00