Skip to content

Commit

Permalink
add debug check that all modes and rawmodes are defined
Browse files Browse the repository at this point in the history
  • Loading branch information
Yay295 committed Jul 16, 2024
1 parent f570219 commit 9526126
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/libImaging/Mode.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
#include "Mode.h"
#include <string.h>

#ifdef NDEBUG
#include <stdio.h>
#include <stdlib.h>
#endif


const ModeData MODES[] = {
[IMAGING_MODE_UNKNOWN] = {""},
Expand Down Expand Up @@ -39,6 +44,11 @@ const ModeID findModeID(const char * const name) {
return IMAGING_MODE_UNKNOWN;
}
for (size_t i = 0; i < sizeof(MODES) / sizeof(*MODES); i++) {
#ifdef NDEBUG
if (MODES[i].name == NULL) {
fprintf(stderr, "Mode ID %zu is not defined.\n", (size_t)i);
} else
#endif
if (strcmp(MODES[i].name, name) == 0) {
return (ModeID)i;
}
Expand Down Expand Up @@ -238,6 +248,11 @@ const RawModeID findRawModeID(const char * const name) {
return IMAGING_RAWMODE_UNKNOWN;
}
for (size_t i = 0; i < sizeof(RAWMODES) / sizeof(*RAWMODES); i++) {
#ifdef NDEBUG
if (RAWMODES[i].name == NULL) {
fprintf(stderr, "Rawmode ID %zu is not defined.\n", (size_t)i);
} else
#endif
if (strcmp(RAWMODES[i].name, name) == 0) {
return (RawModeID)i;
}
Expand Down

0 comments on commit 9526126

Please sign in to comment.