Skip to content

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

@ppisar

Description

@ppisar

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions