aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/common.c14
-rw-r--r--test/test_stub_hints.c6
2 files changed, 17 insertions, 3 deletions
diff --git a/src/common.c b/src/common.c
index f0292ab..663cf28 100644
--- a/src/common.c
+++ b/src/common.c
@@ -212,14 +212,22 @@ puglSetViewHint(PuglView* view, PuglViewHint hint, int value)
}
}
- view->hints[hint] = value;
- return PUGL_SUCCESS;
+ if (hint >= 0 && hint < PUGL_NUM_VIEW_HINTS) {
+ view->hints[hint] = value;
+ return PUGL_SUCCESS;
+ }
+
+ return PUGL_BAD_PARAMETER;
}
int
puglGetViewHint(const PuglView* view, PuglViewHint hint)
{
- return view->hints[hint];
+ if (hint >= 0 && hint < PUGL_NUM_VIEW_HINTS) {
+ return view->hints[hint];
+ }
+
+ return PUGL_DONT_CARE;
}
PuglRect
diff --git a/test/test_stub_hints.c b/test/test_stub_hints.c
index 0ff9e5b..d5331c8 100644
--- a/test/test_stub_hints.c
+++ b/test/test_stub_hints.c
@@ -36,6 +36,12 @@ main(void)
puglSetEventFunc(view, onEvent);
puglSetSizeHint(view, PUGL_DEFAULT_SIZE, 512, 512);
+ // Check invalid cases
+ assert(puglSetViewHint(view, (PuglViewHint)-1, 0) == PUGL_BAD_PARAMETER);
+ assert(puglSetViewHint(view, (PuglViewHint)9999, 0) == PUGL_BAD_PARAMETER);
+ assert(puglGetViewHint(view, (PuglViewHint)-1) == PUGL_DONT_CARE);
+ assert(puglGetViewHint(view, (PuglViewHint)9999) == PUGL_DONT_CARE);
+
// Set all relevant hints that support it to PUGL_DONT_CARE
assert(!puglSetViewHint(view, PUGL_RED_BITS, PUGL_DONT_CARE));
assert(!puglSetViewHint(view, PUGL_GREEN_BITS, PUGL_DONT_CARE));