| 1 |
|
| #include "scan.h" |
| 2 |
|
| |
| 3 |
|
| static void |
| 4 |
121 |
| scan_raw_int(const char** src, STRLEN len, I32* l) { |
| 5 |
|
| STRLEN i; |
| 6 |
|
| I32 m; |
| 7 |
|
| |
| 8 |
121 |
▶ | if (len == 1) /* optimize the common case */ |
Branch: 1 branch
| Branch | True | False | Total |
| if (len == 1) /* optimize the common case */ |
76 |
45 |
121 |
|
| 9 |
76 |
| *l = *(*src)++; |
| 10 |
|
| |
| 11 |
45 |
▶ | else if (len) { |
Branch: 1 branch
| Branch | True | False | Total |
| else if (len) { |
45 |
0 |
45 |
|
| 12 |
45 |
▶ | m = ((**src < 0) ? -1 : 0); |
Branch: 1 branch
| Branch | True | False | Total |
| m = ((**src < 0) ? -1 : 0); |
0 |
45 |
45 |
|
| 13 |
68 |
▶ | for (; (m == **src) && len; (*src)++, len--); /* discard sign bytes */ |
Branch: 2 branches
| Branch | True | False | Total |
| for (; (m == **src) && len; (*src)++, len--); /* discard sign bytes */ |
23 |
45 |
68 |
| for (; (m == **src) && len; (*src)++, len--); /* discard sign bytes */ |
23 |
0 |
23 |
|
| 14 |
|
| |
| 15 |
45 |
▶ | if (len > sizeof(I32)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (len > sizeof(I32)) |
0 |
45 |
45 |
|
| 16 |
0 |
| croak("scan_raw_int: integer overflow"); |
| 17 |
|
| |
| 18 |
141 |
▶ | while (len-- > 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (len-- > 0) { |
96 |
45 |
141 |
|
| 19 |
96 |
| m <<= 8; |
| 20 |
96 |
| m |= *(const unsigned char *)(*src)++; |
| 21 |
|
| } |
| 22 |
45 |
| *l = m; |
| 23 |
|
| } |
| 24 |
|
| |
| 25 |
0 |
| else *l = 0; |
| 26 |
121 |
| } |
| 27 |
|
| |
| 28 |
|
| int |
| 29 |
3 |
| peek_numeric_notag(const char **src, const char *max, I32 *l) { |
| 30 |
|
| STRLEN len; |
| 31 |
3 |
▶ | if (peek_length(src, max, &len)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (peek_length(src, max, &len)) { |
3 |
0 |
3 |
|
| 32 |
3 |
▶ | if (max - *src >= len) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (max - *src >= len) { |
3 |
0 |
3 |
|
| 33 |
3 |
| scan_raw_int(src, len, l); |
| 34 |
3 |
| return 1; |
| 35 |
|
| } |
| 36 |
|
| } |
| 37 |
0 |
| return 0; |
| 38 |
|
| } |
| 39 |
|
| |
| 40 |
|
| int |
| 41 |
0 |
| peek_numeric(const char** src, const char* max, U8 *type, U32* tag, I32* l) { |
| 42 |
0 |
▶ | if (peek_tag(src, max, type, tag)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (peek_tag(src, max, type, tag)) |
0 |
0 |
0 |
|
| 43 |
0 |
| return peek_numeric_notag(src, max, l); |
| 44 |
0 |
| return 0; |
| 45 |
|
| } |
| 46 |
|
| |
| 47 |
|
| void |
| 48 |
118 |
| scan_numeric_notag(const char **src, const char *max, I32 *l) { |
| 49 |
|
| STRLEN len; |
| 50 |
118 |
| scan_length(src, max, &len); |
| 51 |
118 |
| scan_raw_int(src, len, l); |
| 52 |
118 |
| } |
| 53 |
|
| |
| 54 |
|
| void |
| 55 |
0 |
| scan_numeric(const char** src, const char* max, U8 *type, U32* tag, I32* l) { |
| 56 |
0 |
| scan_tag(src, max, type, tag); |
| 57 |
0 |
| scan_numeric_notag(src, max, l); |
| 58 |
0 |
| } |
| 59 |
|
| |
| 60 |
|
| int |
| 61 |
1 |
| peek_numeric_with_small_tt(const char **src, const char *max, |
| 62 |
|
| U8 expected_tt, I32 *val) { |
| 63 |
2 |
▶ | return (peek_small_tag_with_tt(src, max, expected_tt) && |
Branch: 3 branches
| Branch | True | False | Total |
| return (peek_small_tag_with_tt(src, max, expected_tt) && |
1 |
0 |
1 |
| return (peek_small_tag_with_tt(src, max, expected_tt) && |
0 |
1 |
1 |
| return (peek_small_tag_with_tt(src, max, expected_tt) && |
1 |
0 |
1 |
|
| 64 |
1 |
| peek_numeric_notag(src, max, val)); |
| 65 |
|
| } |
| 66 |
|
| |
| 67 |
|
| void |
| 68 |
16 |
| scan_numeric_with_small_tt(const char **src, const char *max, |
| 69 |
|
| U8 expected_tt, I32 *val) { |
| 70 |
16 |
▶ | scan_small_tag_with_tt(src, max, expected_tt); |
Branch: 2 branches
| Branch | True | False | Total |
| scan_small_tag_with_tt(src, max, expected_tt); |
16 |
0 |
16 |
| scan_small_tag_with_tt(src, max, expected_tt); |
16 |
0 |
16 |
|
| 71 |
16 |
| scan_numeric_notag(src, max, val); |
| 72 |
16 |
| } |
| 73 |
|
| |
| 74 |
|
| static void |
| 75 |
22 |
| scan_raw_unsigned_numeric(const char** src, STRLEN len, U32* l) { |
| 76 |
22 |
▶ | if (len == 1) /* optimize the common case */ |
Branch: 1 branch
| Branch | True | False | Total |
| if (len == 1) /* optimize the common case */ |
3 |
19 |
22 |
|
| 77 |
3 |
| *l = *(*src)++; |
| 78 |
|
| |
| 79 |
19 |
▶ | else if (len) { |
Branch: 1 branch
| Branch | True | False | Total |
| else if (len) { |
19 |
0 |
19 |
|
| 80 |
19 |
| U32 m = 0; |
| 81 |
19 |
▶ | if (**src < 0) |
Branch: 1 branch
| Branch | True | False | Total |
| if (**src < 0) |
0 |
19 |
19 |
|
| 82 |
0 |
| croak("scan_raw_unsigned_numeric: bad_packet, signed number found while expecting unsigned"); |
| 83 |
|
| |
| 84 |
28 |
▶ | for (; !(**src) && len; (*src)++, len--); /* discard sign bytes */ |
Branch: 2 branches
| Branch | True | False | Total |
| for (; !(**src) && len; (*src)++, len--); /* discard sign bytes */ |
9 |
19 |
28 |
| for (; !(**src) && len; (*src)++, len--); /* discard sign bytes */ |
9 |
0 |
9 |
|
| 85 |
|
| |
| 86 |
19 |
▶ | if (len > sizeof(I32)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (len > sizeof(I32)) |
0 |
19 |
19 |
|
| 87 |
0 |
| croak("scan_raw_int: integer overflow"); |
| 88 |
|
| |
| 89 |
61 |
▶ | while (len-- > 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (len-- > 0) { |
42 |
19 |
61 |
|
| 90 |
42 |
| m <<= 8; |
| 91 |
42 |
| m |= *(const unsigned char *)(*src)++; |
| 92 |
|
| } |
| 93 |
19 |
| *l = m; |
| 94 |
|
| } |
| 95 |
|
| |
| 96 |
0 |
| else *l = 0; |
| 97 |
22 |
| } |
| 98 |
|
| |
| 99 |
|
| void |
| 100 |
0 |
| scan_unsigned_numeric_notag(const char **src, const char *max, U32 *l) { |
| 101 |
|
| STRLEN len; |
| 102 |
0 |
| scan_length(src, max, &len); |
| 103 |
0 |
| scan_raw_unsigned_numeric(src, len, l); |
| 104 |
0 |
| } |
| 105 |
|
| |
| 106 |
|
| int |
| 107 |
22 |
| peek_unsigned_numeric_notag(const char **src, const char *max, U32 *l) { |
| 108 |
|
| STRLEN len; |
| 109 |
22 |
▶ | if (peek_length(src, max, &len)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (peek_length(src, max, &len)) { |
22 |
0 |
22 |
|
| 110 |
22 |
▶ | if (max - *src >= len) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (max - *src >= len) { |
22 |
0 |
22 |
|
| 111 |
22 |
| scan_raw_unsigned_numeric(src, len, l); |
| 112 |
22 |
| return 1; |
| 113 |
|
| } |
| 114 |
|
| } |
| 115 |
0 |
| return 0; |
| 116 |
|
| } |
| 117 |
|
| |
| 118 |
|
| int |
| 119 |
22 |
| peek_unsigned_numeric_with_small_tt(const char **src, const char *max, |
| 120 |
|
| U8 expected_tt, U32 *val) { |
| 121 |
44 |
▶ | return (peek_small_tag_with_tt(src, max, expected_tt) && |
Branch: 3 branches
| Branch | True | False | Total |
| return (peek_small_tag_with_tt(src, max, expected_tt) && |
22 |
0 |
22 |
| return (peek_small_tag_with_tt(src, max, expected_tt) && |
0 |
22 |
22 |
| return (peek_small_tag_with_tt(src, max, expected_tt) && |
22 |
0 |
22 |
|
| 122 |
22 |
| peek_unsigned_numeric_notag(src, max, val)); |
| 123 |
|
| } |
| 124 |
|
| |
| 125 |
|
| void |
| 126 |
72 |
| scan_unsigned_numeric_with_small_tt(const char **src, const char *max, |
| 127 |
|
| U8 expected_tt, U32 *val) { |
| 128 |
72 |
▶ | scan_small_tag_with_tt(src, max, expected_tt); |
Branch: 2 branches
| Branch | True | False | Total |
| scan_small_tag_with_tt(src, max, expected_tt); |
72 |
0 |
72 |
| scan_small_tag_with_tt(src, max, expected_tt); |
72 |
0 |
72 |
|
| 129 |
72 |
| scan_numeric_notag(src, max, val); |
| 130 |
72 |
| } |