Issue |
134901
|
Summary |
[clang-tidy] Check request: bugprone-memcpy-after-network-to-host
|
Labels |
clang-tidy
|
Assignees |
|
Reporter |
denzor200
|
Needs a check that will find a strange usage of a "network to host" function(like `ntohl` and `ntohs`) before it's result was copied to a raw block of memory.
This check will suggest to change that functions to "host to network" versions because in the most cases this is what the programmers really want.
EXAMPLE:
```
void send(std::uint32_t cook_hdr, std::uint16_t seqnum) {
std::byte packet[6];
cook_hdr = ntohl(cook_hdr); // BAD - looks strange, you mean 'htonl' ??
std::memcpy(&packet[0], &cook_hdr, sizeof(cook_hdr));
seqnum = ntohs(seqnum); // BAD - looks strange, you mean 'htons' ??
std::memcpy(&packet[4], &seqnum, sizeof(seqnum));
send_raw(packet, sizeof(packet));
}
```
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs