Commit c0b1e05
committed
Improve Hashtable_put() buffer grow conditions
The conditions for growing the buffer was off by one. Also improve the
"grow factor" multiplication slightly so that it cannot overflow for any
value <= SIZE_MAX * 7.
If `Hashtable.size > SIZE_MAX / sizeof(HashtableItem)`, the buffer
allocation would fail at xCalloc(), and one conditional for checking
`size` overflow can be omitted. Let compilers omit that as an
optimization.
Signed-off-by: Kang-Che Sung <explorer09@gmail.com>1 parent 041c644 commit c0b1e05
1 file changed
Lines changed: 5 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
222 | 222 | | |
223 | 223 | | |
224 | 224 | | |
| 225 | + | |
225 | 226 | | |
226 | 227 | | |
227 | 228 | | |
228 | | - | |
229 | | - | |
230 | | - | |
| 229 | + | |
| 230 | + | |
231 | 231 | | |
| 232 | + | |
232 | 233 | | |
233 | | - | |
234 | 234 | | |
235 | 235 | | |
236 | 236 | | |
237 | 237 | | |
238 | 238 | | |
239 | | - | |
| 239 | + | |
240 | 240 | | |
241 | 241 | | |
242 | 242 | | |
| |||
0 commit comments