]> Cypherpunks repositories - gostls13.git/commitdiff
internal/coverage/encodecounter: followup changes from code review
authorThan McIntosh <thanm@google.com>
Fri, 5 May 2023 15:11:10 +0000 (11:11 -0400)
committerThan McIntosh <thanm@google.com>
Fri, 5 May 2023 16:49:44 +0000 (16:49 +0000)
This patch contains a small set of changes with fixes for some
issues that surfaced during the code review for CL 484535. Due
to an error on my part, these never got included in the final version
that was checked in (I rebased, mailed the rebase, but then never
mailed the final patch set with the changes). This patch sends
the remaining bits and pieces.

Updates #59563.

Change-Id: I87dc05a83f8e44c8bfe7203bc2b035defc817af9
Reviewed-on: https://go-review.googlesource.com/c/go/+/492981
Run-TryBot: Than McIntosh <thanm@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
src/internal/coverage/encodecounter/encode.go

index 1ff6cb1f9afe99b4da1b6d9c92e630fe4f93f581..59586730de5b8028eaec5c0747daeee8c8252e0c 100644 (file)
@@ -28,7 +28,6 @@ type CoverageDataWriter struct {
        w       *bufio.Writer
        csh     coverage.CounterSegmentHeader
        tmp     []byte
-       nfuncs  uint64
        cflavor coverage.CounterFlavor
        segs    uint32
        debug   bool
@@ -86,17 +85,25 @@ func padToFourByteBoundary(ws *slicewriter.WriteSeeker) error {
 }
 
 func (cfw *CoverageDataWriter) patchSegmentHeader(ws *slicewriter.WriteSeeker) error {
+       // record position
+       off, err := ws.Seek(0, io.SeekCurrent)
+       if err != nil {
+               return fmt.Errorf("error seeking in patchSegmentHeader: %v", err)
+       }
+       // seek back to start so that we can update the segment header
        if _, err := ws.Seek(0, io.SeekStart); err != nil {
                return fmt.Errorf("error seeking in patchSegmentHeader: %v", err)
        }
-       cfw.csh.FcnEntries = cfw.nfuncs
-       cfw.nfuncs = 0
        if cfw.debug {
                fmt.Fprintf(os.Stderr, "=-= writing counter segment header: %+v", cfw.csh)
        }
        if err := binary.Write(ws, binary.LittleEndian, cfw.csh); err != nil {
                return err
        }
+       // ... and finally return to the original offset.
+       if _, err := ws.Seek(off, io.SeekStart); err != nil {
+               return fmt.Errorf("error seeking in patchSegmentHeader: %v", err)
+       }
        return nil
 }
 
@@ -167,8 +174,7 @@ func (cfw *CoverageDataWriter) AppendSegment(args map[string]string, visitor Cou
                cfw.stab.Lookup(v)
        }
 
-       var swws slicewriter.WriteSeeker
-       ws := &swws
+       ws := &slicewriter.WriteSeeker{}
        if err = cfw.writeSegmentPreamble(args, ws); err != nil {
                return err
        }
@@ -253,7 +259,7 @@ func (cfw *CoverageDataWriter) writeCounters(visitor CounterVisitor, ws *slicewr
 
        // Write out entries for each live function.
        emitter := func(pkid uint32, funcid uint32, counters []uint32) error {
-               cfw.nfuncs++
+               cfw.csh.FcnEntries++
                if err := wrval(uint32(len(counters))); err != nil {
                        return err
                }