Using a C-style cast to convert pointer types to a byte-like pointer type has many issues:
- It may accidentally and silently throw away
const. - It forces reviewers to check that it doesn't accidentally throw away
const.
For example, on current master a const char* is cast to unsigned char* (without const), see https://github.com/bitcoin/bitcoin/blob/d23fda05842ba4539b225bbab01b94df0060f697/src/span.h#L273 . This can lead to UB, and the only reason why it didn't lead to UB is because the return type added back the const. (Obviously this would break if the return type was deduced via auto)
Fix all issues by adding back the const and using reinterpret_cast where appropriate.