[PATCH] D78904: [clang-tidy] extend bugprone-signed-char-misuse check with array subscript case.

Tamás Zolnai via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 27 02:06:02 PDT 2020


ztamas created this revision.
Herald added subscribers: cfe-commits, xazax.hun.
Herald added a project: clang.
ztamas added a reviewer: aaron.ballman.
ztamas added a comment.
ztamas updated this revision to Diff 260243.

I run the check both on LibreOffice and LLVM codebase but did not find any catch. I expect that it's not a frequent use case.
I added this extension only to fully cover the CERT rule. If this patch is accepted I can add a cert alias for this check.


ztamas added a comment.

Fix typo


To cover STR34-C rule's second use case, where ``signed char`` is
used for array subscript after an integer conversion. In the case
of non-ASCII character a ``signed char`` will result in a value
in excess of UCHAR_MAX because of integer promotion.

There is another clang-tidy check which catches these cases.
cppcoreguidelines-pro-bounds-constant-array-index catches any
indexing which is not integer constant. I think this check is
very strict about the index (e.g. constant), so it's still useful
to cover the ``signed char`` use case in this check, so we
can provide a way to catch the SEI cert rule's use cases on a
codebase, where this CPP guideline is not used.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D78904

Files:
  clang-tools-extra/clang-tidy/bugprone/SignedCharMisuseCheck.cpp
  clang-tools-extra/docs/clang-tidy/checks/bugprone-signed-char-misuse.rst
  clang-tools-extra/test/clang-tidy/checkers/bugprone-signed-char-misuse.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D78904.260243.patch
Type: text/x-patch
Size: 5567 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200427/f119c17f/attachment-0001.bin>


More information about the cfe-commits mailing list