You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README/README-CONVENTIONS.md
+65-1Lines changed: 65 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -143,4 +143,68 @@ db := util.GetDB()
143
143
144
144
- When there is no meaningful dependency that needs to be passed.
145
145
- When it makes the code unnecessarily complex.
146
-
- When simple handler functions would be more readable and sufficient.
146
+
- When simple handler functions would be more readable and sufficient.
147
+
148
+
### 32-Bit Platform Compatibility
149
+
150
+
**Convention UUID: CONV-32BIT-001**
151
+
152
+
* When parsing string values to uint64 and then converting to platform-specific uint types, always validate that the value fits within the platform's uint size to prevent overflow on 32-bit systems.
153
+
* This convention addresses security concerns identified by GitHub's CodeQL analysis and ensures cross-platform compatibility.
154
+
155
+
#### The Problem
156
+
157
+
* On 64-bit platforms, `uint` is 64 bits and can hold any `uint64` value safely.
158
+
* On 32-bit platforms, `uint` is only 32 bits, so large `uint64` values will overflow when converted to `uint`.
159
+
* Direct conversion without validation can lead to unexpected behavior and potential security issues.
160
+
161
+
#### Recommended Implementation
162
+
163
+
Use named constants to make the platform detection logic clear and self-documenting:
164
+
165
+
```go
166
+
// Platform detection constants for 32-bit compatibility check
167
+
const (
168
+
bitsInByte = 8
169
+
bytesInUint32 = 4
170
+
rightShiftFor64BitDetection = 63
171
+
baseBitWidth = 32
172
+
)
173
+
174
+
// Detect platform bit width using named constants
0 commit comments