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 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 */
167const 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
You can’t perform that action at this time.
0 commit comments