MCPcopy Create free account
hub / github.com/GJDuck/e9patch / scanf_get_hex

Function scanf_get_hex

examples/stdlib.c:4364–4388  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4362}
4363
4364static __attribute__((__noinline__)) bool scanf_get_hex(
4365 struct scanf_stream_s *in, size_t *width, uint64_t *p, bool *r)
4366{
4367 char c = scanf_get_char_n(in, width);
4368 if (!isxdigit(c))
4369 {
4370 scanf_unget_char_n(c, in, width);
4371 return false;
4372 }
4373 uint64_t i = 0;
4374 do
4375 {
4376 i *= 16;
4377 uint64_t d = (c >= '0' && c <= '9'? c - '0':
4378 c >= 'a' && c <= 'f'? 10 + c - 'a':
4379 c >= 'A' && c <= 'F'? 10 + c - 'A': 0);
4380 if (UINT64_MAX - i < d)
4381 *r = true;
4382 i = (UINT64_MAX - i < d? UINT64_MAX: i + d);
4383 }
4384 while (isxdigit(c = scanf_get_char_n(in, width)));
4385 scanf_unget_char_n(c, in, width);
4386 *p = i;
4387 return true;
4388}
4389
4390static __attribute__((__noinline__)) bool scanf_get_num(
4391 struct scanf_stream_s *in, size_t width, unsigned flags, void *ptr)

Callers 1

scanf_get_numFunction · 0.85

Calls 3

scanf_get_char_nFunction · 0.85
isxdigitFunction · 0.85
scanf_unget_char_nFunction · 0.85

Tested by

no test coverage detected