MCPcopy Create free account
hub / github.com/coreboot/coreboot / Check_This_Field

Function Check_This_Field

payloads/libpayload/curses/form/fty_num.c:180–280  ·  view source on GitHub ↗

--------------------------------------------------------------------------- | Facility : libnform | Function : static bool Check_This_Field(FIELD * field, | const void * argp) | | Description : Validate buffer content to be a valid numeric value | | Return Values : TRUE - field is valid | FALSE - field is i

Source from the content-addressed store, hash-verified

178| FALSE - field is invalid
179+--------------------------------------------------------------------------*/
180static bool
181Check_This_Field(FIELD *field, const void *argp)
182{
183 const thisARG *argn = (const thisARG *)argp;
184 double low = argn->low;
185 double high = argn->high;
186 int prec = argn->precision;
187 unsigned char *bp = (unsigned char *)field_buffer(field, 0);
188 char *s = (char *)bp;
189 double val = 0.0;
190 struct lconv *L = argn->L;
191 char buf[64];
192 bool result = FALSE;
193
194 while (*bp && *bp == ' ')
195 bp++;
196 if (*bp)
197 {
198 if (*bp == '-' || *bp == '+')
199 bp++;
200#if USE_WIDEC_SUPPORT
201 if (*bp)
202 {
203 bool blank = FALSE;
204 int state = 0;
205 int len;
206 int n;
207 wchar_t *list = _nc_Widen_String((char *)bp, &len);
208
209 if (list != 0)
210 {
211 result = TRUE;
212 for (n = 0; n < len; ++n)
213 {
214 if (blank)
215 {
216 if (list[n] != ' ')
217 {
218 result = FALSE;
219 break;
220 }
221 }
222 else if (list[n] == ' ')
223 {
224 blank = TRUE;
225 }
226 else if (isDecimalPoint(list[n]))
227 {
228 if (++state > 1)
229 {
230 result = FALSE;
231 break;
232 }
233 }
234 else if (!isDigit(list[n]))
235 {
236 result = FALSE;
237 break;

Callers

nothing calls this directly

Calls 6

field_bufferFunction · 0.85
_nc_Widen_StringFunction · 0.85
sprintfFunction · 0.85
set_field_bufferFunction · 0.85
freeFunction · 0.50
isdigitFunction · 0.50

Tested by

no test coverage detected