[PATCH] D137379: [-Wunsafe-buffer-usage] Add warnings for unsafe buffer accesses by array subscript operations
Manoj Gupta via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Mar 27 10:48:40 PDT 2023
manojgupta added a comment.
This is firing even in checked length codes, is that expected?
example:
https://godbolt.org/z/Todje76ao
std::optional<uint16_t> result;
bool ReadDevice(uint8_t* data, size_t len) {
if (!result)
return false;
memset(data, 0, len);
if (len > 0) data[0] = (result.value() >> 8) & 0xFF;
if (len > 1) data[1] = result.value() & 0xFF;
return true;
}
<source>:7:26: warning: 'data' is an unsafe pointer used for buffer access [-Wunsafe-buffer-usage]
bool ReadDevice(uint8_t* data, size_t len) {
~~~~~~~~~^~~~
<source>:13:20: note: used in buffer access here
if (len > 1) data[1] = result.value() & 0xFF;
^~~~
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D137379/new/
https://reviews.llvm.org/D137379
More information about the cfe-commits
mailing list