Commit 850ca5a
committed
Fix strict aliasing violation in
There might be platform where addressing the user provided array of unknown
alignment as `uint32_t` would be incorrect. Generally the previous code violates
strict aliasing and thus invokes UB. By using the "magic" properties of `memcpy`
we can sidestep the issue by letting it do the load and store for us. In
practice this means on platforms where addressing the memory as 4 byte regions
is safe and efficient to do - which is most widely used platforms - the compiler
can insert the appropriate `mov` instructions inline and if a platform does not
support this operation it will likely insert a call to the `memcpy` function.swap function1 parent aecca52 commit 850ca5a
1 file changed
+14
-19
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
15 | | - | |
16 | 14 | | |
17 | 15 | | |
18 | 16 | | |
| |||
48 | 46 | | |
49 | 47 | | |
50 | 48 | | |
| 49 | + | |
| 50 | + | |
51 | 51 | | |
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
67 | 64 | | |
68 | 65 | | |
69 | | - | |
70 | | - | |
71 | 66 | | |
72 | 67 | | |
73 | 68 | | |
| |||
118 | 113 | | |
119 | 114 | | |
120 | 115 | | |
121 | | - | |
122 | | - | |
123 | | - | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
124 | 119 | | |
125 | 120 | | |
126 | 121 | | |
| |||
0 commit comments