aggressive: []byte from netip.Addr.AsSlice should not be printed with %s #1503
Labels
aggressive
A set of checks that is more prone to false positives but is helpful during code review
new-check
(This could technically be a part of a larger feature regarding printability of
[]byte
, but I've decided to only file the one I've met in the wild. Feel free to retitle/expand.)Initial code:
With
processAsSlice
accepting[]byte
.After some time,
process
starts to acceptnetip.Addr
instead ofnet.IP
. So, a refactoring is made:This looks okay, except that
netip.Addr.AsSlice
returns[]byte
, notnet.IP
. So,fmt.Printf
doesn't print, say,1.2.3.4
, but rather the bytes with the values\x01\x02\x03\x04
.https://go.dev/play/p/NqBf12NH69O
There is technically a possibility that someone actually wants to print those bytes, so I'm proposing this one for the aggressive mode, but I also feel like 99 % of this sort of code is a bug.
The text was updated successfully, but these errors were encountered: