Commit 76be096
committed
small: fix false-positive 'out of array bound' error
Static allocator uses a global char[] array to
hand it out in chunks. The array addressing was done
via '&buffer[index]', but GCC compiler thinks that
there is an out of bound array access, when sees
something like static_alloc(max_size + 1).
Having static_alloc() inlined it somewhy thinks, that
this size is used as an index of the static buffer,
despite the fact, that such sizes are filtered out in
'if's before indexing the buffer.
This test was leading to the compilation error:
test/static.c:78:
static_alloc(SMALL_STATIC_SIZE + 1)
Static_alloc checks if a current position + size >
max_size, then check is size > max_size, and then
returns NULL, the test checks it. But GCC can't detect
that, and thinks that this code makes
'buffer[max_size + 1]'.
This commit uses pointer arithmetic instead of address
operator to avoid this bogus error.1 parent 45710a9 commit 76be096
2 files changed
+7
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
78 | 78 | | |
79 | 79 | | |
80 | 80 | | |
81 | | - | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
82 | 86 | | |
83 | 87 | | |
84 | 88 | | |
| |||
120 | 124 | | |
121 | 125 | | |
122 | 126 | | |
123 | | - | |
| 127 | + | |
124 | 128 | | |
125 | 129 | | |
126 | 130 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
38 | | - | |
| 38 | + | |
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
| |||
0 commit comments