Commit ce9f291
authored
fix(circular): trim initial elements to capacity (#50)
* test(circular): add failing test for Reset exceeding capacity
Constructing a Circular queue with 5 elements and capacity=3 should
trim to 3 in every sense, including Reset. Current main stores all 5
as the reset target, so Reset restores size=5 on a 3-slot backing
array, corrupting subsequent reads.
Refs #40
* fix(circular): cap initialElems at capacity
NewCircular trims the live elems slice to capacity but kept the full
givenElems as the reset target. Reset would then restore a size
larger than the backing array, making subsequent Get/Contains/Iterator
read or iterate past the array's valid region.
Trim initialElems to capacity so Reset produces a valid state.
Fixes #401 parent d360b8c commit ce9f291
2 files changed
Lines changed: 56 additions & 17 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
51 | | - | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
52 | 59 | | |
53 | 60 | | |
54 | 61 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
260 | 260 | | |
261 | 261 | | |
262 | 262 | | |
263 | | - | |
| 263 | + | |
264 | 264 | | |
265 | | - | |
| 265 | + | |
| 266 | + | |
266 | 267 | | |
267 | | - | |
268 | | - | |
269 | | - | |
270 | | - | |
| 268 | + | |
271 | 269 | | |
272 | | - | |
273 | | - | |
274 | | - | |
275 | | - | |
| 270 | + | |
276 | 271 | | |
277 | | - | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
278 | 276 | | |
279 | | - | |
280 | | - | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
281 | 281 | | |
282 | | - | |
283 | | - | |
284 | | - | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
285 | 317 | | |
286 | 318 | | |
287 | 319 | | |
| |||
0 commit comments