Files
Florian Lehnerandzeekay 9d40d96a8a [pdata/pprofile] fix off-by one Dictionary issue (#14534)
<!--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]>
2026-02-22 00:54:49 -08:00

37 lines
1.0 KiB
Go

// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package pprofile // import "go.opentelemetry.io/collector/pdata/pprofile"
import "fmt"
// switchDictionary updates the ValueType, switching its indices from one
// dictionary to another.
func (ms ValueType) switchDictionary(src, dst ProfilesDictionary) error {
if ms.TypeStrindex() > 0 {
if src.StringTable().Len() <= int(ms.TypeStrindex()) {
return fmt.Errorf("invalid type index %d", ms.TypeStrindex())
}
idx, err := SetString(dst.StringTable(), src.StringTable().At(int(ms.TypeStrindex())))
if err != nil {
return fmt.Errorf("couldn't set type: %w", err)
}
ms.SetTypeStrindex(idx)
}
if ms.UnitStrindex() > 0 {
if src.StringTable().Len() <= int(ms.UnitStrindex()) {
return fmt.Errorf("invalid unit index %d", ms.UnitStrindex())
}
idx, err := SetString(dst.StringTable(), src.StringTable().At(int(ms.UnitStrindex())))
if err != nil {
return fmt.Errorf("couldn't set unit: %w", err)
}
ms.SetUnitStrindex(idx)
}
return nil
}