aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
diff options
context:
space:
mode:
authoreinvbri <vince.a.bridgers@ericsson.com>2022-07-07 04:38:56 -0500
committereinvbri <vince.a.bridgers@ericsson.com>2022-07-13 19:19:23 -0500
commit1d7e58cfade1dd4236efba59ce969698bb05a039 (patch)
treedac2ff8072e8c714817616f6865cd64147a0e87a /clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
parentddd4ed99445dba17ccffc22a9d74a5448745a466 (diff)
downloadllvm-1d7e58cfade1dd4236efba59ce969698bb05a039.zip
llvm-1d7e58cfade1dd4236efba59ce969698bb05a039.tar.gz
llvm-1d7e58cfade1dd4236efba59ce969698bb05a039.tar.bz2
[analyzer] Fix use of length in CStringChecker
CStringChecker is using getByteLength to get the length of a string literal. For targets where a "char" is 8-bits, getByteLength() and getLength() will be equal for a C string, but for targets where a "char" is 16-bits getByteLength() returns the size in octets. This is verified in our downstream target, but we have no way to add a test case for this case since there is no target supporting 16-bit "char" upstream. Since this cannot have a test case, I'm asserted this change is "correct by construction", and visually inspected to be correct by way of the following example where this was found. The case that shows this fails using a target with 16-bit chars is here. getByteLength() for the string literal returns 4, which fails when checked against "char x[4]". With the change, the string literal is evaluated to a size of 2 which is a correct number of "char"'s for a 16-bit target. ``` void strcpy_no_overflow_2(char *y) { char x[4]; strcpy(x, "12"); // with getByteLength(), returns 4 using 16-bit chars } ``` This change exposed that embedded nulls within the string are not handled. This is documented as a FIXME for a future fix. ``` void strcpy_no_overflow_3(char *y) { char x[3]; strcpy(x, "12\0"); } ``` Reviewed By: martong Differential Revision: https://reviews.llvm.org/D129269
Diffstat (limited to 'clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp')
0 files changed, 0 insertions, 0 deletions