Skip to content
This repository was archived by the owner on Apr 17, 2026. It is now read-only.
This repository was archived by the owner on Apr 17, 2026. It is now read-only.

_assert_false Function implementation logic error, causing the assertion judgment result to be reversed #73

@azxvv

Description

@azxvv

title

_assert_false Function implementation logic error, causing the assertion judgment result to be reversed

Problem description

The conditional judgment logic of a function is completely opposite to the function name and expected behavior:
When the input parameter result is 0 (false), the function triggers an error
When the input parameter result is non-zero (true), the function asserts through an assertion
This leads to the use of assert_false(condition) in test cases, where the actual expected condition is true (non-zero), which contradicts the original intention of the function design.

Reproduce steps

void test_assert_false(void **state) {
    int result = 0;
    assert_false(result);  // 期望通过,但实际失败
}

but output it

expected 'result' to be false
ERROR: test.c:123 Failure!

Debugging shows that the value of 'result' is indeed 0, but the '_assert_false ' function incorrectly triggered an assertion failure

Reason for the problem

in src/cmockery. c

void _assert_true(const LargestIntegralType result,
                  const char * const expression,
                  const char * const file, const int line) {
    if (!result) {
        print_error("expected '%s' to be true\n", expression);
        _fail(file, line);
    }
}


void _assert_false(const LargestIntegralType result,
                  const char * const expression,
                  const char * const file, const int line) {
    if (!result) {
        print_error("expected '%s' to be false\n", expression);
        _fail(file, line);
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions