Wrap wxCHECK macro inside a do{}while construct to protect it (PR #26096)

12 views
Skip to first unread message

Ian McInerney

unread,
Jan 12, 2026, 4:22:10 PM (2 days ago) Jan 12
to wx-...@googlegroups.com, Subscribed

Before, it is just a bare if statement, which could pose issues if used as the only statement in a single-line control flow construct, where the else clause could get associated with the wrong if statement, and the ending semicolon wrapper would get associated with the wrong nesting level.

We saw this get flagged in a Coverity scan check in KiCad when we had code like:

    if( !tmpPath.empty() )
        tmpPath.pop_back();
    else
        wxCHECK_MSG( false, /* void */, wxS( "Sheet paths must have a least one valid sheet." ) );

and Coverity then said that the macro wxCHECK_MSG had bad nesting level (the trailing semicolon would end up outside the if/else statement here).

It could also be problematic if someone tried the flow

if(something)
    wxCHECK_MSG( false, ...)

because then the else clause in the macro would actually bind to the wrong if statement (the one written by the user, not the one in the macro).

Also, this makes the wxCHECK implementations consistent with wxFAIL_COND_MSG_AT and wxASSERT_MSG_AT, which use this statement wrapper.


You can view, comment on, or merge this pull request online at:

  https://github.com/wxWidgets/wxWidgets/pull/26096

Commit Summary

  • 5029e98 Wrap wxCHECK macro inside a do{}while construct to protect it

File Changes

(1 file)

Patch Links:


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/26096@github.com>

Reply all
Reply to author
Forward
0 new messages