net: internal dtoi and xtoi helpers have unusual API #16350
Closed
Labels
Milestone
Comments
Yes, those weird me out every time I encounter them. |
CL https://golang.org/cl/27206 mentions this issue. |
CL https://golang.org/cl/28414 mentions this issue. |
gopherbot
pushed a commit
that referenced
this issue
Sep 7, 2016
https://golang.org/cl/27206 fixed the dtoi function such that it now properly parses negative number. Ironically, this causes several other functions that depended on dtoi to now (incorrectly) parse negative numbers. For example, ParseCIDR("-1.0.0.0/32") used to be rejected prior to the above CL, but is now accepted even though it is an invalid CIDR notation. This CL fixes that regression. We fix this by removing the signed parsing logic entirely from dtoi. It was introduced relatively recently in https://golang.org/cl/12447 to fix a bug where an invalid port was improperly being parsed as OK. It seems to me that the fix in that CL to the port handling logic was sufficient such that a change to dtoi was unnecessary. Updates #16350 Change-Id: I414bb1aa27d0a226ebd4b05a09cb40d784691b43 Reviewed-on: https://go-review.googlesource.com/28414 Reviewed-by: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Mikio Hara <mikioh.mikioh@gmail.com> Run-TryBot: Joe Tsai <thebrokentoaster@gmail.com>
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
These internal helpers have signatures like:
and they parse an integer value from
&s[i0]
. Especially since the majority of callers usei0==0
, it seems like it would be simpler / more idiomatic to just have the caller passs[i0:]
as an argument.In particular, dtoi theoretically supports parsing negative integers, except it looks for the
'-'
character ats[0]
, nots[i0]
./cc @bradfitz @dpiddy
The text was updated successfully, but these errors were encountered: