File tree Expand file tree Collapse file tree 1 file changed +11
-19
lines changed Expand file tree Collapse file tree 1 file changed +11
-19
lines changed Original file line number Diff line number Diff line change 3
3
/* LibTomMath, multiple-precision integer library -- Tom St Denis */
4
4
/* SPDX-License-Identifier: Unlicense */
5
5
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
-
15
6
/* return a char * string for a given code */
16
7
const char * mp_error_to_string (int code )
17
8
{
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" ;
25
20
}
26
-
27
- /* generic reply for invalid code */
28
- return "Invalid error code" ;
29
21
}
30
22
31
23
#endif
You can’t perform that action at this time.
0 commit comments