git: d16bc4fda821 - stable/13 - atf: Guard against multiple evaluation.
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Mon, 20 May 2024 09:35:07 UTC
The branch stable/13 has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=d16bc4fda8215adab6b1c219ec2edd862fd757ac commit d16bc4fda8215adab6b1c219ec2edd862fd757ac Author: Dag-Erling Smørgrav <des@FreeBSD.org> AuthorDate: 2024-05-15 10:08:44 +0000 Commit: Dag-Erling Smørgrav <des@FreeBSD.org> CommitDate: 2024-05-20 09:04:59 +0000 atf: Guard against multiple evaluation. Note that the ATF-C++ macros have the same issue, but they are not as easily fixed. MFC after: 3 days Reviewed by: ngie Differential Revision: https://reviews.freebsd.org/D45148 (cherry picked from commit a7beca6fb113986839de73b7cf73d933464898c6) --- contrib/atf/atf-c/macros.h | 151 ++++++++++++++++++++++++++++----------------- 1 file changed, 95 insertions(+), 56 deletions(-) diff --git a/contrib/atf/atf-c/macros.h b/contrib/atf/atf-c/macros.h index 1784fc47435d..abcb9f697907 100644 --- a/contrib/atf/atf-c/macros.h +++ b/contrib/atf/atf-c/macros.h @@ -167,65 +167,104 @@ ATF_CHECK_MSG((expected) == (actual), "%s != %s: " fmt, \ #expected, #actual, ##__VA_ARGS__) -#define ATF_REQUIRE_STREQ(expected, actual) \ - ATF_REQUIRE_MSG(strcmp(expected, actual) == 0, "%s != %s (%s != %s)", \ - #expected, #actual, expected, actual) - -#define ATF_CHECK_STREQ(expected, actual) \ - ATF_CHECK_MSG(strcmp(expected, actual) == 0, "%s != %s (%s != %s)", \ - #expected, #actual, expected, actual) - -#define ATF_REQUIRE_STREQ_MSG(expected, actual, fmt, ...) \ - ATF_REQUIRE_MSG(strcmp(expected, actual) == 0, \ - "%s != %s (%s != %s): " fmt, \ - #expected, #actual, expected, actual, ##__VA_ARGS__) - -#define ATF_CHECK_STREQ_MSG(expected, actual, fmt, ...) \ - ATF_CHECK_MSG(strcmp(expected, actual) == 0, \ - "%s != %s (%s != %s): " fmt, \ - #expected, #actual, expected, actual, ##__VA_ARGS__) - -#define ATF_REQUIRE_INTEQ(expected, actual) \ - ATF_REQUIRE_MSG((expected) == (actual), "%s != %s (%jd != %jd)", \ - #expected, #actual, (intmax_t)(expected), \ - (intmax_t)(actual)) - -#define ATF_CHECK_INTEQ(expected, actual) \ - ATF_CHECK_MSG((expected) == (actual), "%s != %s (%jd != %jd)", #expected, \ - #actual, (intmax_t)(expected), (intmax_t)(actual)) - -#define ATF_REQUIRE_INTEQ_MSG(expected, actual, fmt, ...) \ - ATF_REQUIRE_MSG((expected) == (actual), "%s != %s (%jd != %jd): " fmt, \ - #expected, #actual, (intmax_t)(expected), \ - (intmax_t)(actual), ##__VA_ARGS__) - -#define ATF_CHECK_INTEQ_MSG(expected, actual, fmt, ...) \ - ATF_CHECK_MSG((expected) == (actual), "%s != %s (%jd != %jd): " fmt, \ - #expected, #actual, (intmax_t)(expected), \ - (intmax_t)(actual), ##__VA_ARGS__) - -#define ATF_REQUIRE_MATCH(regexp, string) \ - ATF_REQUIRE_MSG(atf_utils_grep_string("%s", string, regexp), \ - "'%s' not matched in '%s'", regexp, string); - -#define ATF_CHECK_MATCH(regexp, string) \ - ATF_CHECK_MSG(atf_utils_grep_string("%s", string, regexp), \ - "'%s' not matched in '%s'", regexp, string); - -#define ATF_REQUIRE_MATCH_MSG(regexp, string, fmt, ...) \ - ATF_REQUIRE_MSG(atf_utils_grep_string("%s", string, regexp), \ - "'%s' not matched in '%s': " fmt, regexp, string, \ - ##__VA_ARGS__); - -#define ATF_CHECK_MATCH_MSG(regexp, string, fmt, ...) \ - ATF_CHECK_MSG(atf_utils_grep_string("%s", string, regexp), \ - "'%s' not matched in '%s': " fmt, regexp, string, \ - ##__VA_ARGS__); +#define ATF_REQUIRE_STREQ(expected, actual) do { \ + const char *_atf_expected = (expected); \ + const char *_atf_actual = (actual); \ + ATF_REQUIRE_MSG(strcmp(_atf_expected, _atf_actual) == 0, \ + "%s != %s (%s != %s)", #expected, #actual, \ + _atf_expected, _atf_actual); \ + } while (0) + +#define ATF_CHECK_STREQ(expected, actual) do { \ + const char *_atf_expected = (expected); \ + const char *_atf_actual = (actual); \ + ATF_CHECK_MSG(strcmp(_atf_expected, _atf_actual) == 0, \ + "%s != %s (%s != %s)", #expected, #actual, \ + _atf_expected, _atf_actual); \ + } while (0) + +#define ATF_REQUIRE_STREQ_MSG(expected, actual, fmt, ...) do { \ + const char *_atf_expected = (expected); \ + const char *_atf_actual = (actual); \ + ATF_REQUIRE_MSG(strcmp(_atf_expected, _atf_actual) == 0, \ + "%s != %s (%s != %s): " fmt, #expected, #actual, \ + _atf_expected, _atf_actual, ##__VA_ARGS__); \ + } while (0) + +#define ATF_CHECK_STREQ_MSG(expected, actual, fmt, ...) do { \ + const char *_atf_expected = (expected); \ + const char *_atf_actual = (actual); \ + ATF_CHECK_MSG(strcmp(_atf_expected, _atf_actual) == 0, \ + "%s != %s (%s != %s): " fmt, #expected, #actual, \ + _atf_expected, _atf_actual, ##__VA_ARGS__); \ + } while (0) + +#define ATF_REQUIRE_INTEQ(expected, actual) do { \ + intmax_t _atf_expected = (expected); \ + intmax_t _atf_actual = (actual); \ + ATF_REQUIRE_MSG(_atf_expected == _atf_actual, \ + "%s != %s (%jd != %jd)", #expected, #actual, \ + _atf_expected, _atf_actual); \ + } while (0) + +#define ATF_CHECK_INTEQ(expected, actual) do { \ + intmax_t _atf_expected = (expected); \ + intmax_t _atf_actual = (actual); \ + ATF_CHECK_MSG(_atf_expected == _atf_actual, \ + "%s != %s (%jd != %jd)", #expected, #actual, \ + _atf_expected, _atf_actual); \ + } while (0) + +#define ATF_REQUIRE_INTEQ_MSG(expected, actual, fmt, ...) do { \ + intmax_t _atf_expected = (expected); \ + intmax_t _atf_actual = (actual); \ + ATF_REQUIRE_MSG(_atf_expected == _atf_actual, \ + "%s != %s (%jd != %jd): " fmt, #expected, #actual, \ + _atf_expected, _atf_actual, ##__VA_ARGS__); \ + } while (0) + +#define ATF_CHECK_INTEQ_MSG(expected, actual, fmt, ...) do { \ + intmax_t _atf_expected = (expected); \ + intmax_t _atf_actual = (actual); \ + ATF_CHECK_MSG(_atf_expected == _atf_actual, \ + "%s != %s (%jd != %jd): " fmt, #expected, #actual, \ + _atf_expected, _atf_actual, ##__VA_ARGS__); \ + } while (0) + +#define ATF_REQUIRE_MATCH(regexp, string) do { \ + const char *_atf_regexp = (regexp); \ + const char *_atf_string = (string); \ + ATF_REQUIRE_MSG(atf_utils_grep_string("%s", _atf_string, _atf_regexp), \ + "'%s' not matched in '%s'", _atf_regexp, _atf_string); \ + } while (0) + +#define ATF_CHECK_MATCH(regexp, string) do { \ + const char *_atf_regexp = (regexp); \ + const char *_atf_string = (string); \ + ATF_CHECK_MSG(atf_utils_grep_string("%s", _atf_string, _atf_regexp), \ + "'%s' not matched in '%s'", _atf_regexp, _atf_string); \ + } while (0) + +#define ATF_REQUIRE_MATCH_MSG(regexp, string, fmt, ...) do { \ + const char *_atf_regexp = (regexp); \ + const char *_atf_string = (string); \ + ATF_REQUIRE_MSG(atf_utils_grep_string("%s", _atf_string, _atf_regexp), \ + "'%s' not matched in '%s': " fmt, _atf_regexp, _atf_string, \ + ##__VA_ARGS__); \ + } while (0) + +#define ATF_CHECK_MATCH_MSG(regexp, string, fmt, ...) do { \ + const char *_atf_regexp = (regexp); \ + const char *_atf_string = (string); \ + ATF_CHECK_MSG(atf_utils_grep_string("%s", _atf_string, _atf_regexp), \ + "'%s' not matched in '%s': " fmt, _atf_regexp, _atf_string, \ + ##__VA_ARGS__); \ + } while (0) #define ATF_CHECK_ERRNO(exp_errno, bool_expr) \ - atf_tc_check_errno(__FILE__, __LINE__, exp_errno, #bool_expr, bool_expr) + atf_tc_check_errno(__FILE__, __LINE__, (exp_errno), #bool_expr, (bool_expr)) #define ATF_REQUIRE_ERRNO(exp_errno, bool_expr) \ - atf_tc_require_errno(__FILE__, __LINE__, exp_errno, #bool_expr, bool_expr) + atf_tc_require_errno(__FILE__, __LINE__, (exp_errno), #bool_expr, (bool_expr)) #endif /* !defined(ATF_C_MACROS_H) */