Commit dfc71a4
authored
Add Support For All SIgned and Unsigned Integers (#3787)
* feat(int): add support for all signed integers
Signed-off-by: Rodney Osodo <socials@rodneyosodo.com>
* feat(uint): add support for all unsigned integer types
uint, uint8, uint16, uint32, uint64
* style: fix unnecessary conversion
* fix(int): Potential overflow when casting uint64 to int64.
If v > math.MaxInt64 the cast silently wraps around, turning a large positive value into a negative one and slipping past the size-checks in safeCastSignedNumber, yielding incorrect results instead of a deterministic overflow error.
* fix(uint): wrong max constants for signed branches.
safeCastUnsignedNumber treats "int8"/"int16"/"int32" the same as their unsigned counterparts and compares against math.MaxUint*.
Casting a value 200 into int8 passes the check (200 ≤ 255) and returns int8(200) which is -56 after wrap-around.
* fix: group cases in switch statement
Signed-off-by: Rodney Osodo <socials@rodneyosodo.com>
* test: remove unnecessary tests cases
Signed-off-by: Rodney Osodo <socials@rodneyosodo.com>
* test: add benchmark tests for UnmarshalUint and UnmarshalInt
These are the results from my local setup:
goos: linux
goarch: amd64
pkg: github.com/99designs/gqlgen/graphql
cpu: AMD Ryzen 7 7735HS with Radeon Graphics
BenchmarkUnmarshalIntInitial-16 62162 19745 ns/op
BenchmarkUnmarshalIntNew-16 53192 22884 ns/op
BenchmarkUnmarshalUintInitial-16 18339 67228 ns/op
BenchmarkUnmarshalUintNew-16 54229 22213 ns/op
PASS
ok github.com/99designs/gqlgen/graphql6.208s
Signed-off-by: Rodney Osodo <socials@rodneyosodo.com>
---------
Signed-off-by: Rodney Osodo <socials@rodneyosodo.com>1 parent 14f4431 commit dfc71a4
4 files changed
+617
-174
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
13 | | - | |
| 14 | + | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
| 19 | + | |
32 | 20 | | |
33 | 21 | | |
34 | | - | |
| 22 | + | |
35 | 23 | | |
36 | | - | |
| 24 | + | |
37 | 25 | | |
38 | 26 | | |
39 | 27 | | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
55 | 40 | | |
56 | 41 | | |
57 | 42 | | |
58 | 43 | | |
59 | | - | |
| 44 | + | |
60 | 45 | | |
61 | 46 | | |
62 | 47 | | |
63 | 48 | | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
64 | 67 | | |
| 68 | + | |
| 69 | + | |
65 | 70 | | |
66 | 71 | | |
67 | 72 | | |
68 | 73 | | |
69 | 74 | | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
| 75 | + | |
75 | 76 | | |
76 | 77 | | |
77 | 78 | | |
78 | 79 | | |
79 | 80 | | |
80 | | - | |
| 81 | + | |
81 | 82 | | |
82 | 83 | | |
83 | 84 | | |
84 | | - | |
| 85 | + | |
85 | 86 | | |
86 | 87 | | |
87 | 88 | | |
| |||
98 | 99 | | |
99 | 100 | | |
100 | 101 | | |
101 | | - | |
102 | | - | |
| 102 | + | |
| 103 | + | |
103 | 104 | | |
104 | 105 | | |
105 | 106 | | |
106 | | - | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | | - | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
112 | 127 | | |
113 | 128 | | |
114 | 129 | | |
115 | | - | |
| 130 | + | |
116 | 131 | | |
117 | 132 | | |
118 | 133 | | |
119 | | - | |
120 | | - | |
121 | | - | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
122 | 157 | | |
123 | | - | |
| 158 | + | |
| 159 | + | |
124 | 160 | | |
0 commit comments