Merge pull request #220 from libtom/missing_error_code Add handling of MP_ITER error-code to mp_error_to_string()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
diff --git a/bn_mp_error_to_string.c b/bn_mp_error_to_string.c
index 0e2af44..59595eb 100644
--- a/bn_mp_error_to_string.c
+++ b/bn_mp_error_to_string.c
@@ -3,29 +3,21 @@
/* LibTomMath, multiple-precision integer library -- Tom St Denis */
/* SPDX-License-Identifier: Unlicense */
-static const struct {
- int code;
- const char *msg;
-} msgs[] = {
- { MP_OKAY, "Successful" },
- { MP_MEM, "Out of heap" },
- { MP_VAL, "Value out of range" }
-};
-
/* return a char * string for a given code */
const char *mp_error_to_string(int code)
{
- size_t x;
-
- /* scan the lookup table for the given message */
- for (x = 0; x < (sizeof(msgs) / sizeof(msgs[0])); x++) {
- if (msgs[x].code == code) {
- return msgs[x].msg;
- }
+ switch (code) {
+ case MP_OKAY:
+ return "Successful";
+ case MP_MEM:
+ return "Out of heap";
+ case MP_VAL:
+ return "Value out of range";
+ case MP_ITER:
+ return "Max. iterations reached";
+ default:
+ return "Invalid error code";
}
-
- /* generic reply for invalid code */
- return "Invalid error code";
}
#endif