mirror of
https://github.com/hanzoai/telemetry.git
synced 2026-10-30 20:01:49 +00:00
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> #### Description Fix off-by-one issue in dictionary lookups. <!-- Issue number if applicable --> #### Link to tracking issue Fixes # <!--Describe what testing was performed and which tests were added.--> #### Testing <!--Describe the documentation added.--> #### Documentation <!--Please delete paragraphs that you did not use before submitting.--> Signed-off-by: Florian Lehner <[email protected]>
57 lines
1.7 KiB
Go
57 lines
1.7 KiB
Go
// Copyright The OpenTelemetry Authors
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package pprofile // import "go.opentelemetry.io/collector/pdata/pprofile"
|
|
|
|
import "fmt"
|
|
|
|
// Equal checks equality with another Function
|
|
func (fn Function) Equal(val Function) bool {
|
|
return fn.NameStrindex() == val.NameStrindex() &&
|
|
fn.SystemNameStrindex() == val.SystemNameStrindex() &&
|
|
fn.FilenameStrindex() == val.FilenameStrindex() &&
|
|
fn.StartLine() == val.StartLine()
|
|
}
|
|
|
|
// switchDictionary updates the Function, switching its indices from one
|
|
// dictionary to another.
|
|
func (fn Function) switchDictionary(src, dst ProfilesDictionary) error {
|
|
if fn.NameStrindex() > 0 {
|
|
if src.StringTable().Len() <= int(fn.NameStrindex()) {
|
|
return fmt.Errorf("invalid name index %d", fn.NameStrindex())
|
|
}
|
|
|
|
idx, err := SetString(dst.StringTable(), src.StringTable().At(int(fn.NameStrindex())))
|
|
if err != nil {
|
|
return fmt.Errorf("couldn't set name: %w", err)
|
|
}
|
|
fn.SetNameStrindex(idx)
|
|
}
|
|
|
|
if fn.SystemNameStrindex() > 0 {
|
|
if src.StringTable().Len() <= int(fn.SystemNameStrindex()) {
|
|
return fmt.Errorf("invalid system name index %d", fn.SystemNameStrindex())
|
|
}
|
|
|
|
idx, err := SetString(dst.StringTable(), src.StringTable().At(int(fn.SystemNameStrindex())))
|
|
if err != nil {
|
|
return fmt.Errorf("couldn't set system name: %w", err)
|
|
}
|
|
fn.SetSystemNameStrindex(idx)
|
|
}
|
|
|
|
if fn.FilenameStrindex() > 0 {
|
|
if src.StringTable().Len() <= int(fn.FilenameStrindex()) {
|
|
return fmt.Errorf("invalid filename index %d", fn.FilenameStrindex())
|
|
}
|
|
|
|
idx, err := SetString(dst.StringTable(), src.StringTable().At(int(fn.FilenameStrindex())))
|
|
if err != nil {
|
|
return fmt.Errorf("couldn't set filename: %w", err)
|
|
}
|
|
fn.SetFilenameStrindex(idx)
|
|
}
|
|
|
|
return nil
|
|
}
|