Commit 9ff496e
committed
libscript: Tweak MCScriptForeignInvocation to help Coverity
The `MCScriptForeignInvocation` implementation is confusing Coverity,
which is reporting a bunch of uninitialised memory errors relating to
pointers acquired via the `MCScriptForeignInvocation::Allocate()`
method. There were two possible problems:
- The maximum storage allocatable was stored in
`MCScriptForeignInvocation::m_storage_limit`, a mutable member
variable (despite being a compile-time constant). It's possible
that Coverity was assuming that it could be mutated at some point to
be larger than the size of the fixed-size `m_stack_storage` array,
allowing `Allocate()` to return a pointer to invalid memory. This
patch removes the member.
- `MCScriptForeignInvocation::ReferenceArgument()` and `Argument()`
were checking whether the current argument count was _equal_ to the
maximum number of arguments, rather than checking that it was less
than the maximum. This could allow Coverity to assume that the
current argument count was greater than the maximum number of
arguments, once again allowing pointers to invalid memory to be
produced. This patch introduces inequalities.
Coverity-Id: 137925
Coverity-Id: 1379271 parent 9115ea4 commit 9ff496e
1 file changed
Lines changed: 4 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
44 | | - | |
45 | | - | |
| 44 | + | |
46 | 45 | | |
47 | 46 | | |
48 | 47 | | |
| |||
71 | 70 | | |
72 | 71 | | |
73 | 72 | | |
74 | | - | |
| 73 | + | |
75 | 74 | | |
76 | 75 | | |
77 | 76 | | |
| |||
92 | 91 | | |
93 | 92 | | |
94 | 93 | | |
95 | | - | |
| 94 | + | |
96 | 95 | | |
97 | 96 | | |
98 | 97 | | |
| |||
114 | 113 | | |
115 | 114 | | |
116 | 115 | | |
117 | | - | |
| 116 | + | |
118 | 117 | | |
119 | 118 | | |
120 | 119 | | |
| |||
180 | 179 | | |
181 | 180 | | |
182 | 181 | | |
183 | | - | |
184 | 182 | | |
185 | 183 | | |
186 | 184 | | |
| |||
0 commit comments