* Internal helper function to parse a numeric for a failpoint term. */
| 1071 | * Internal helper function to parse a numeric for a failpoint term. |
| 1072 | */ |
| 1073 | static char * |
| 1074 | parse_number(int *out_units, int *out_decimal, char *p) |
| 1075 | { |
| 1076 | char *old_p; |
| 1077 | |
| 1078 | /** |
| 1079 | * <number> :: |
| 1080 | * <integer> [ "." <integer> ] | |
| 1081 | * "." <integer> |
| 1082 | */ |
| 1083 | |
| 1084 | /* whole part */ |
| 1085 | old_p = p; |
| 1086 | *out_units = strtol(p, &p, 10); |
| 1087 | if (p == old_p && *p != '.') |
| 1088 | return (NULL); |
| 1089 | |
| 1090 | /* fractional part */ |
| 1091 | *out_decimal = 0; |
| 1092 | if (*p == '.') { |
| 1093 | int digits = 0; |
| 1094 | p++; |
| 1095 | while (isdigit(*p)) { |
| 1096 | int digit = *p - '0'; |
| 1097 | if (digits < PROB_DIGITS - 2) |
| 1098 | *out_decimal = *out_decimal * 10 + digit; |
| 1099 | else if (digits == PROB_DIGITS - 2 && digit >= 5) |
| 1100 | (*out_decimal)++; |
| 1101 | digits++; |
| 1102 | p++; |
| 1103 | } |
| 1104 | if (!digits) /* need at least one digit after '.' */ |
| 1105 | return (NULL); |
| 1106 | while (digits++ < PROB_DIGITS - 2) /* add implicit zeros */ |
| 1107 | *out_decimal *= 10; |
| 1108 | } |
| 1109 | |
| 1110 | return (p); /* success */ |
| 1111 | } |
| 1112 | |
| 1113 | /** |
| 1114 | * Internal helper function to parse an individual type for a failpoint term. |
no test coverage detected