Skip to content

Commit a105bc9

Browse files
authored
Merge pull request #220 from libtom/missing_error_code
Add handling of MP_ITER error-code to mp_error_to_string()
2 parents 3d51fe1 + 2b6e9d0 commit a105bc9

File tree

1 file changed

+11
-19
lines changed

1 file changed

+11
-19
lines changed

bn_mp_error_to_string.c

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,21 @@
33
/* LibTomMath, multiple-precision integer library -- Tom St Denis */
44
/* SPDX-License-Identifier: Unlicense */
55

6-
static const struct {
7-
int code;
8-
const char *msg;
9-
} msgs[] = {
10-
{ MP_OKAY, "Successful" },
11-
{ MP_MEM, "Out of heap" },
12-
{ MP_VAL, "Value out of range" }
13-
};
14-
156
/* return a char * string for a given code */
167
const char *mp_error_to_string(int code)
178
{
18-
size_t x;
19-
20-
/* scan the lookup table for the given message */
21-
for (x = 0; x < (sizeof(msgs) / sizeof(msgs[0])); x++) {
22-
if (msgs[x].code == code) {
23-
return msgs[x].msg;
24-
}
9+
switch (code) {
10+
case MP_OKAY:
11+
return "Successful";
12+
case MP_MEM:
13+
return "Out of heap";
14+
case MP_VAL:
15+
return "Value out of range";
16+
case MP_ITER:
17+
return "Max. iterations reached";
18+
default:
19+
return "Invalid error code";
2520
}
26-
27-
/* generic reply for invalid code */
28-
return "Invalid error code";
2921
}
3022

3123
#endif

0 commit comments

Comments
 (0)