Date: Wed, 03 May 2023 14:00:41 +0000 From: bugzilla-noreply@freebsd.org To: bugs@FreeBSD.org Subject: [Bug 271227] ATF_REQUIRE_EQ cannot be used with static_cast<const char *>(NULL) Message-ID: <bug-271227-227@https.bugs.freebsd.org/bugzilla/>
next in thread | raw e-mail | index | archive | help
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D271227 Bug ID: 271227 Summary: ATF_REQUIRE_EQ cannot be used with static_cast<const char *>(NULL) Product: Base System Version: CURRENT Hardware: Any OS: Any Status: New Severity: Affects Only Me Priority: --- Component: misc Assignee: bugs@FreeBSD.org Reporter: emaste@freebsd.org In contrib/atf/atf-c/macros.h we have: #define ATF_REQUIRE_EQ(expected, actual) \ ATF_REQUIRE_MSG((expected) =3D=3D (actual), "%s !=3D %s", #expected, #a= ctual) #define ATF_REQUIRE_STREQ(expected, actual) \ ATF_REQUIRE_MSG(strcmp(expected, actual) =3D=3D 0, "%s !=3D %s (%s !=3D= %s)", \ #expected, #actual, expected, actual) ATF_REQUIRE_EQ tests that the (arbitrary) arguments are equal, while ATF_REQUIRE_STREQ compares (and prints differing) strings. In contrast, in contrib/atf/atf-c++/macros.hpp we have only ATF_REQUIRE_EQ: #define ATF_REQUIRE_EQ(expected, actual) \ do { \ if ((expected) !=3D (actual)) { \ std::ostringstream atfu_ss; \ atfu_ss << "Line " << __LINE__ << ": " \ << #expected << " !=3D " << #actual \ << " (" << (expected) << " !=3D " << (actual) << ")"; \ atf::tests::tc::fail(atfu_ss.str()); \ } \ } while (false) In lib/libnv/tests/cnv_tests.cc we have: ATF_REQUIRE_EQ(nvlist_next(nvl, &type, &cookie), static_cast<const char *>(NULL)); which GCC warns will pass NULL to a fn with a nonnull arg: In file included from /usr/obj/tmp/cirrus-ci-build/amd64.amd64/tmp/usr/include/c++/v1/string:536: In static member function 'static constexpr size_t std::__1::char_traits<char>::length(const char_type*)', inlined from 'std::__1::basic_ostream<char, _Traits>& std::__1::operator<<(basic_ostream<char, _Traits>&, const char*) [with _Tra= its =3D char_traits<char>]' at /usr/obj/tmp/cirrus-ci-build/amd64.amd64/tmp/usr/include/c++/v1/ostream:902= :43, inlined from 'virtual void {anonymous}::atfu_tc_cnvlist_free_nvlist_array::body() const' at /tmp/cirrus-ci-build/lib/libnv/tests/cnv_tests.cc:1438:3: /usr/obj/tmp/cirrus-ci-build/amd64.amd64/tmp/usr/include/c++/v1/__string/ch= ar_traits.h:218:30: warning: argument 1 null where non-null expected [-Wnonnull] 218 | return __builtin_strlen(__s); | ~~~~~~~~~~~~~~~~^~~~~ --=20 You are receiving this mail because: You are the assignee for the bug.=
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?bug-271227-227>