Closed traetox closed 4 years ago
So scanf definitely can parse things like "0x" as 0, as in:
package main
import (
"fmt"
"os"
"strings"
)
func main() {
var i int
r := strings.NewReader("0x")
n, err := fmt.Fscanf(r, "%x", &i)
if err != nil {
fmt.Fprintf(os.Stderr, "Fscanf: %v\n", err)
}
fmt.Println(i)
fmt.Println(n)
}
But strconv.ParseInt doesn't follow scanf's behavior, as in:
package main
import (
"fmt"
"strconv"
)
func main() {
v := "0x"
s, err := strconv.ParseInt(v, 0, 64)
if err != nil {
fmt.Println(err)
}
fmt.Printf("%T, %v\n", s, s)
}
The latter program will error with "0x invalid syntax".
So these are broken tests/assertions about how to parse thing. Did we write these tests or did these come from upstream?
I should add that the parser in gcfg is using strconv.ParseInt
I did not write those tests. Are they broken upstream?
On Fri, Jun 12, 2020, 12:31 PM David Fritz notifications@github.com wrote:
I should add that the parser in gcfg is using strconv.ParseInt
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/gravwell/gcfg/issues/2#issuecomment-643424519, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAKD2OFZQ7WAK4VA25HBXO3RWJX7BANCNFSM4N4Q3XBA .
They must be - there's a comment in the tests asserting that scanf
works on empty prefixes (0x, 0b, ...) which it does (even C stdlib does this), but then they use strconv
to parse everything, which doesn't at all follow the scanf behavior...
So either the test is wrong or the expectation of their implementation is wrong. I patched for the test...
These tests appear to be wrong, some of these integers CLEARLY shouldn't be accepted.
Whats up here? Is this just a bad test? Did we break these?