Skip to content

Commit c3c968e

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

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/libImaging/Mode.c

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

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

59
const ModeData MODES[] = {
610
[IMAGING_MODE_UNKNOWN] = {""},
@@ -39,6 +43,11 @@ const ModeID findModeID(const char * const name) {
3943
return IMAGING_MODE_UNKNOWN;
4044
}
4145
for (size_t i = 0; i < sizeof(MODES) / sizeof(*MODES); i++) {
46+
#ifdef NDEBUG
47+
if (MODES[i].name == NULL) {
48+
fprintf(stderr, "Mode ID %zu is not defined.\n", (size_t)i);
49+
} else
50+
#endif
4251
if (strcmp(MODES[i].name, name) == 0) {
4352
return (ModeID)i;
4453
}
@@ -238,6 +247,11 @@ const RawModeID findRawModeID(const char * const name) {
238247
return IMAGING_RAWMODE_UNKNOWN;
239248
}
240249
for (size_t i = 0; i < sizeof(RAWMODES) / sizeof(*RAWMODES); i++) {
250+
#ifdef NDEBUG
251+
if (RAWMODES[i].name == NULL) {
252+
fprintf(stderr, "Rawmode ID %zu is not defined.\n", (size_t)i);
253+
} else
254+
#endif
241255
if (strcmp(RAWMODES[i].name, name) == 0) {
242256
return (RawModeID)i;
243257
}

0 commit comments

Comments
 (0)