]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
fd-util: make TAKE_FD free of double evaluation
authorLennart Poettering <lennart@poettering.net>
Tue, 2 Nov 2021 16:52:24 +0000 (17:52 +0100)
committerLennart Poettering <lennart@poettering.net>
Wed, 3 Nov 2021 14:22:18 +0000 (15:22 +0100)
Better be safe than sorry.

src/basic/fd-util.h

index dd5207bd88a8c84fd851fae5c96c0543b81b023a..f5cfcb4edeb79af46292c8870c040121aa77f4b5 100644 (file)
@@ -91,9 +91,10 @@ static inline int make_null_stdio(void) {
 /* Like TAKE_PTR() but for file descriptors, resetting them to -1 */
 #define TAKE_FD(fd)                             \
         ({                                      \
-                int _fd_ = (fd);                \
-                (fd) = -1;                      \
-                _fd_;                           \
+                int *_fd_ = &(fd);              \
+                int _ret_ = *_fd_;              \
+                *_fd_ = -1;                     \
+                _ret_;                          \
         })
 
 /* Like free_and_replace(), but for file descriptors */