Skip to content

Commit 495184f

Browse files
Potential fix for code scanning alert no. 54: Incorrect conversion between integer types
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
1 parent cf32e10 commit 495184f

2 files changed

Lines changed: 4 additions & 4 deletions

File tree

providers/openapi/schema/parse_xml.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,11 +167,11 @@ func parseValue(s string, ref *Schema) (interface{}, error) {
167167
t := ref.Type
168168

169169
if t.IsInteger() {
170-
v, err := strconv.Atoi(s)
170+
val64, err := strconv.ParseInt(s, 10, 32)
171171
if err != nil {
172172
return nil, fmt.Errorf("parse integer failed: %v", s)
173173
}
174-
return v, nil
174+
return int32(val64), nil
175175
}
176176

177177
if t.IsNumber() {

schema/json/parser/parser_integer.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ func (p *Parser) ParseInteger(i interface{}, s *schema.Schema) (interface{}, err
3838
}
3939
switch s.Format {
4040
case "int32":
41-
n32, err := strconv.Atoi(v)
41+
val64, err := strconv.ParseInt(v, 10, 32)
4242
if err != nil {
4343
return 0, &ErrorDetail{
4444
Message: fmt.Sprintf("invalid type, expected %v but got %v", s.Type, toType(i)),
4545
Field: "type",
4646
}
4747
}
48-
n = int64(n32)
48+
n = val64
4949
default:
5050
var err error
5151
n, err = strconv.ParseInt(v, 10, 64)

0 commit comments

Comments
 (0)