You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The Go spec says that constant float values should not be convertible to integer values. Gno guards against conversion of untyped float constants, but not typed constants. For example, both of these examples work in Gno when they should not:
package main
funcmain() {
println(int(float64(1.5)))
}
package main
funcmain() {
constvfloat64=1.5println(int(v))
}
To interpret the above, it is necessary to know if a typed constant float value x is representable as an integer. Looking at the definition of constant representability:
A constant x is representable by a value of type T, where T is not a type parameter, if one of the following conditions applies:
T is a floating-point type and x can be rounded to T's precision without overflow. Rounding uses IEEE 754 round-to-even rules but with an IEEE negative zero further simplified to an unsigned zero. Note that constant values never result in an IEEE negative zero, NaN, or infinity.
T is a complex type, and x's components real(x) and imag(x) are representable by values of T's component type (float32 or float64).
In the case of this particular issue, typed float constant values are not representable as integers because they fail to to satisfy and of the criteria -- most notably that a non-natural number is not contained in the set of possible integer values.
Other Examples
All of these are examples that work in Gno but should not.
Integer Underflow
package main
funcmain() {
constaint=-1println(uint(a))
}
Integer Overflow
package main
funcmain() {
constaint=270println(uint8(a))
}
The text was updated successfully, but these errors were encountered:
deelawn
changed the title
bug(gnovm): prohibit conversion of typed constants
bug(gnovm): prohibit conversion of non-convertible typed constants
Aug 12, 2024
High Level Summary
The Go spec says that constant float values should not be convertible to integer values. Gno guards against conversion of untyped float constants, but not typed constants. For example, both of these examples work in Gno when they should not:
Details
From the Go spec:
To interpret the above, it is necessary to know if a typed constant float value x is representable as an integer. Looking at the definition of constant representability:
In the case of this particular issue, typed float constant values are not representable as integers because they fail to to satisfy and of the criteria -- most notably that a non-natural number is not contained in the set of possible integer values.
Other Examples
All of these are examples that work in Gno but should not.
Integer Underflow
Integer Overflow
The text was updated successfully, but these errors were encountered: