Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fail(), fail_if(), or fail_unless() warns about "too many arguments for format" because of an extra NULL argument #359

Open
ppisar opened this issue Jan 16, 2025 · 0 comments

Comments

@ppisar
Copy link

ppisar commented Jan 16, 2025

Compiling fail(), fail_if(), or fail_unless() macros emits a warning like this:

/builddir/build/BUILD/libdnf-0.73.4-build/libdnf-0.73.4/tests/hawkey/test_goal.cpp:439:18: warning: too many arguments for format [-Wformat-extra-args]
  439 |             fail("assert_list_names(): list too short");
      |                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The cause is that the macros pass an extra NULL argument:

#define fail(...) _ck_assert_failed(__FILE__, __LINE__, "Failed" , ## __VA_ARGS__, NULL)

to _ck_assert_failed() function declared with check for a printf formatting string:

CK_DLL_EXP void CK_EXPORT _ck_assert_failed(const char *file, int line,
                                            const char *expr, const char *msg,
                                            ...) CK_ATTRIBUTE_NORETURN CK_ATTRIBUTE_FORMAT(printf, 4, 5);

Then the exampled macro expands to:

_ck_assert_failed("FILE", LINE, "Failed", "assert_list_names(): list too short", NULL);

where the NULL argument is superfluous.

Observed with check-0.15.2 and gcc-15.0.1.

I guess the NULL argument should be removed as in ck_assert_msg() definition. Though, maybe you keep the deprecated macros broken on purposes, to preserve compatibility.

@ppisar ppisar changed the title fail(), fail_if(), or fail_unless() warns about "too many arguments for format" becaue of an extra NULL argument fail(), fail_if(), or fail_unless() warns about "too many arguments for format" because of an extra NULL argument Jan 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant