From b9cba1443bc9d964e681968195e29b637aca8b7d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Vladim=C3=ADr=20=C4=8Cun=C3=A1t?= Date: Wed, 7 Oct 2020 09:51:16 +0200 Subject: [PATCH] contrib/cleanup: be more correct It's mainly about the fact that FD can be zero (though it's not common). Our current usage is just in tests and seems fine. I don't think that other negative FDs are possible, but I'm lazy to find "proof" in POSIX and using other negative values than -1 doesn't make sense to me anyway (might be an assert, I guess). --- contrib/cleanup.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/cleanup.h b/contrib/cleanup.h index ba5343f63..1a51aad38 100644 --- a/contrib/cleanup.h +++ b/contrib/cleanup.h @@ -16,7 +16,7 @@ static inline void _cleanup_free(char **p) { } #define auto_close __attribute__((cleanup(_cleanup_close))) static inline void _cleanup_close(int *p) { - if (*p > 0) close(*p); + if (*p != -1) close(*p); } #define auto_fclose __attribute__((cleanup(_cleanup_fclose))) static inline void _cleanup_fclose(FILE **p) { -- 2.47.2