diff --git a/common/controls.c b/common/controls.c index 096bc6b2..4819a0bb 100644 --- a/common/controls.c +++ b/common/controls.c @@ -204,6 +204,15 @@ void *uiControlImplData(uiControl *c) return c->implData; } +static uiControl testHookControlWithInvalidControlMarker = { + .controlID = 5, +}; + +uiControl *uiprivTestHookControlWithInvalidControlMarker(void) +{ + return &testHookControlWithInvalidControlMarker; +} + static uiControl testHookControlWithInvalidType = { .controlID = controlTypeID, .typeID = 5, diff --git a/common/testhooks.h b/common/testhooks.h index a6076001..54984692 100644 --- a/common/testhooks.h +++ b/common/testhooks.h @@ -9,6 +9,7 @@ typedef void (*uiprivTestHookReportProgrammerErrorFunc)(const char *msg, void *d uiprivExtern void uiprivTestHookReportProgrammerError(uiprivTestHookReportProgrammerErrorFunc f, void *data); // controls.c +uiprivExtern uiControl *uiprivTestHookControlWithInvalidControlMarker(void); uiprivExtern uiControl *uiprivTestHookControlWithInvalidType(void); #ifdef __cplusplus diff --git a/test/controls_errors.cpp b/test/controls_errors.cpp index 783f2cc5..686cfded 100644 --- a/test/controls_errors.cpp +++ b/test/controls_errors.cpp @@ -64,12 +64,20 @@ static const struct checkErrorCase casesAfterOSVtable[] = { { "uiCheckControlType() with non-control", [](void) { - static char buf[] = "this is not a uiControl"; + // TODO make sure this is fine; if not, just use the following check instead + static char buf[] = "this is not a uiControl but is big enough to at the very least not cause a problem with UB hopefully"; uiCheckControlType(buf, uiControlType()); }, "uiCheckControlType(): object passed in not a uiControl", }, + { + "uiCheckControlType() with uiControl without uiControlType() marker", + [](void) { + uiCheckControlType(uiprivTestHookControlWithInvalidControlMarker(), uiControlType()); + }, + "uiCheckControlType(): object passed in not a uiControl", + }, { "uiCheckControlType() with a control with an unknown type", [](void) {