From eb3d3f367ea09b89d54f177ded1e874611d1020f Mon Sep 17 00:00:00 2001 From: Stefano Brivio Date: Tue, 5 Apr 2022 11:51:47 +0200 Subject: treewide: Argument cannot be negative, CWE-687 Actually harmless. Reported by Coverity. Signed-off-by: Stefano Brivio --- util.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'util.h') diff --git a/util.h b/util.h index 91ce3e0..5172bf6 100644 --- a/util.h +++ b/util.h @@ -58,6 +58,18 @@ void trace_init(int enable); #define TMPDIR "/tmp" #endif +#define FWRITE(path, buf, str) \ + do { \ + int flags = O_WRONLY | O_CLOEXEC; \ + int fd = open(path, flags); \ + \ + if (fd < 0 || \ + write(fd, buf, strlen(buf)) != (int)strlen(buf)) \ + warn(str); \ + if (fd >= 0) \ + close(fd); \ + } while (0) + #define V4 0 #define V6 1 #define IP_VERSIONS 2 -- cgit v1.2.3