Skip to content

Commit c4c90e3

Browse files
committed
add debug check that all modes and rawmodes are defined
1 parent 0d94531 commit c4c90e3

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/libImaging/Mode.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
#include "Mode.h"
22
#include <string.h>
33

4+
#ifdef NDEBUG
5+
#include <stdio.h>
6+
#include <stdlib.h>
7+
#endif
8+
49

510
const ModeData MODES[] = {
611
[IMAGING_MODE_UNKNOWN] = {""},
@@ -39,6 +44,11 @@ const ModeID findModeID(const char * const name) {
3944
return IMAGING_MODE_UNKNOWN;
4045
}
4146
for (size_t i = 0; i < sizeof(MODES) / sizeof(*MODES); i++) {
47+
#ifdef NDEBUG
48+
if (MODES[i].name == NULL) {
49+
fprintf(stderr, "Mode ID %zu is not defined.\n", (size_t)i);
50+
} else
51+
#endif
4252
if (strcmp(MODES[i].name, name) == 0) {
4353
return (ModeID)i;
4454
}
@@ -238,6 +248,11 @@ const RawModeID findRawModeID(const char * const name) {
238248
return IMAGING_RAWMODE_UNKNOWN;
239249
}
240250
for (size_t i = 0; i < sizeof(RAWMODES) / sizeof(*RAWMODES); i++) {
251+
#ifdef NDEBUG
252+
if (RAWMODES[i].name == NULL) {
253+
fprintf(stderr, "Rawmode ID %zu is not defined.\n", (size_t)i);
254+
} else
255+
#endif
241256
if (strcmp(RAWMODES[i].name, name) == 0) {
242257
return (RawModeID)i;
243258
}

0 commit comments

Comments
 (0)