|
1 |
| -/* |
2 |
| -Copyright (c) 2015 VMware, Inc. All Rights Reserved. |
3 |
| -
|
4 |
| -Licensed under the Apache License, Version 2.0 (the "License"); |
5 |
| -you may not use this file except in compliance with the License. |
6 |
| -You may obtain a copy of the License at |
7 |
| -
|
8 |
| - http://www.apache.org/licenses/LICENSE-2.0 |
9 |
| -
|
10 |
| -Unless required by applicable law or agreed to in writing, software |
11 |
| -distributed under the License is distributed on an "AS IS" BASIS, |
12 |
| -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13 |
| -See the License for the specific language governing permissions and |
14 |
| -limitations under the License. |
15 |
| -*/ |
| 1 | +// © Broadcom. All Rights Reserved. |
| 2 | +// The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. |
| 3 | +// SPDX-License-Identifier: Apache-2.0 |
16 | 4 |
|
17 | 5 | package object
|
18 | 6 |
|
19 | 7 | import (
|
20 | 8 | "context"
|
21 | 9 | "errors"
|
| 10 | + "math" |
22 | 11 | "strconv"
|
23 | 12 |
|
24 | 13 | "github.com/vmware/govmomi/vim25"
|
@@ -127,9 +116,12 @@ func (m CustomFieldsManager) FindKey(ctx context.Context, name string) (int32, e
|
127 | 116 | }
|
128 | 117 | }
|
129 | 118 |
|
130 |
| - k, err := strconv.Atoi(name) |
131 |
| - if err == nil { |
132 |
| - // assume literal int key |
| 119 | + k, err := strconv.ParseInt(name, 10, 32) |
| 120 | + if err != nil { |
| 121 | + return -1, ErrKeyNameNotFound |
| 122 | + } |
| 123 | + |
| 124 | + if k >= math.MinInt32 && k <= math.MaxInt32 { |
133 | 125 | return int32(k), nil
|
134 | 126 | }
|
135 | 127 |
|
|
0 commit comments