This is an archive of the discontinued LLVM Phabricator instance.

[clang-tidy] Add checker for operations between integrals and pointers
ClosedPublic

Authored by etienneb on Apr 14 2016, 8:30 AM.

Details

Summary

This check is finding suspicious operations involving pointers and integral types; which are most likely bugs.

Examples:
subversion/v1_6/subversion/libsvn_subr/utf.c

static const char *
fuzzy_escape(const char *src, apr_size_t len, apr_pool_t *pool)
{
  [...]
   while (src_orig < src_end)
    {
      if (! svn_ctype_isascii(*src_orig) || src_orig == '\0')   // Should be *src_orig
        {

apache2/v2_2_23/modules/metadata/mod_headers.c

static char *parse_format_tag(apr_pool_t *p, format_tag *tag, const char **sa)
{
  [...]
    tag->arg = '\0';   // ERROR: tag->arg has type char*

    /* grab the argument if there is one */
    if (*s == '{') {
        ++s;
        tag->arg = ap_getword(p,&s,'}');
    }

Diff Detail

Event Timeline

etienneb updated this revision to Diff 53728.Apr 14 2016, 8:30 AM
etienneb retitled this revision from to [clang-tidy] Add checker for operations between integrals and pointers.
etienneb updated this object.
etienneb added a reviewer: alexfh.
etienneb added a subscriber: cfe-commits.
alexfh accepted this revision.Apr 14 2016, 9:19 AM
alexfh edited edge metadata.

LG. Nice check!

test/clang-tidy/misc-pointer-and-integral-operation-cxx98.cpp
10

Specify the whole message including the check name once.

This revision is now accepted and ready to land.Apr 14 2016, 9:19 AM
Eugene.Zelenko added inline comments.
docs/clang-tidy/checks/misc-pointer-and-integral-operation.rst
10

Looks like excessive line.

23

Process?

etienneb updated this revision to Diff 53903.Apr 15 2016, 9:34 AM
etienneb marked 3 inline comments as done.
etienneb edited edge metadata.

comments.

docs/clang-tidy/checks/misc-pointer-and-integral-operation.rst
23

tpo. oups.. typo :)

etienneb closed this revision.Apr 15 2016, 9:36 AM