{"action":"opened","issue":{"url":"https://api.github.com/repos/golang/go/issues/17781","repository_url":"https://api.github.com/repos/golang/go","labels_url":"https://api.github.com/repos/golang/go/issues/17781/labels{/name}","comments_url":"https://api.github.com/repos/golang/go/issues/17781/comments","events_url":"https://api.github.com/repos/golang/go/issues/17781/events","html_url":"https://github.com/golang/go/issues/17781","id":187179279,"number":17781,"title":"use EncodedLen function consistenly in \"encoding/hex\" package Decode functions","user":{"login":"OpsMx","id":20037432,"avatar_url":"https://avatars.githubusercontent.com/u/20037432?v=3","gravatar_id":"","url":"https://api.github.com/users/OpsMx","html_url":"https://github.com/OpsMx","followers_url":"https://api.github.com/users/OpsMx/followers","following_url":"https://api.github.com/users/OpsMx/following{/other_user}","gists_url":"https://api.github.com/users/OpsMx/gists{/gist_id}","starred_url":"https://api.github.com/users/OpsMx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/OpsMx/subscriptions","organizations_url":"https://api.github.com/users/OpsMx/orgs","repos_url":"https://api.github.com/users/OpsMx/repos","events_url":"https://api.github.com/users/OpsMx/events{/privacy}","received_events_url":"https://api.github.com/users/OpsMx/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-11-03T20:21:19Z","updated_at":"2016-11-03T20:21:19Z","closed_at":null,"body":"\r\n### What version of Go are you using (`go version`)?\r\ngo version go1.6 linux/amd64\r\n\r\n### What operating system and processor architecture are you using (`go env`)?\r\nlinux(ubuntu 14.04) and amd64\r\n\r\n### What did you do?\r\nThe DecodeString function in hex.go is used to return the bytes represented by a hexadecimal string.This function internally invokes the decode function by passing it dest and src slices.So the length of des slice is calculated using DecodedLen function ,but it is not used consistently in both these functions.\r\n\r\nhttps://github.com/golang/go/blob/master/src/encoding/hex/hex.go#L97\r\nIn DecodeString function ,DecodedLen function is used to create a dest slice.This is half the length of src slice.\r\nNow in the same DecodeString function Decode(dst, src) function is invoked in which it is mentioned as below.But inside this function in the for loop ,len(src)/2 is used for filling up the dest slice.So I feel it would be better to use the same DecodedLen(len(src)) in this function as well so as to be consistent and also as per what is mentioned in this methods doc.\r\n\r\n\"Decode decodes src into DecodedLen(len(src)) bytes,returning the actual number of bytes written to dst. \"\r\n\r\nWould be interested to work on this change,if the community feels this change is fine to be incorporated.This is not any bug or performance improvement as such but to make the code consistent and clean.\r\n"}}
{"actor":{"display_login":"OpsMx"}}