Skip to content

Commit f5da9a0

Browse files
runtime/coverage: fix snapshot total calculation
Fixes #62212
1 parent 08cdfd0 commit f5da9a0

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

src/internal/coverage/defs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ func Round4(x int) int {
371371
// numCtrs uint32
372372
// pkgid uint32
373373
// funcid uint32
374-
// counterArray [numBlocks]uint32
374+
// counterArray [numCtrs]uint32
375375
// }
376376
//
377377
// where "numCtrs" is the number of blocks / coverable units within the

src/runtime/coverage/testsupport.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,19 +294,22 @@ func snapshot() float64 {
294294
totExec := uint64(0)
295295
for _, c := range cl {
296296
sd := unsafe.Slice((*atomic.Uint32)(unsafe.Pointer(c.Counters)), c.Len)
297-
tot += uint64(len(sd))
298297
for i := 0; i < len(sd); i++ {
298+
nCtrs := sd[i+coverage.NumCtrsOffset].Load()
299+
299300
// Skip ahead until the next non-zero value.
300-
if sd[i].Load() == 0 {
301+
if nCtrs == 0 {
301302
continue
302303
}
304+
303305
// We found a function that was executed.
304-
nCtrs := sd[i+coverage.NumCtrsOffset].Load()
305306
cst := i + coverage.FirstCtrOffset
306307

307308
if cst+int(nCtrs) > len(sd) {
308309
break
309310
}
311+
312+
tot += uint64(nCtrs)
310313
counters := sd[cst : cst+int(nCtrs)]
311314
for i := range counters {
312315
if counters[i].Load() != 0 {

0 commit comments

Comments
 (0)