Skip to content

RULE-18-1: Picky about how pointers are tracked, doesn't consider derefs before 1 from end, or array-to-pointer conversions #840

Open
@MichaelRFairhurst

Description

@MichaelRFairhurst

Affected rules

  • RULE-18-1
  • M5-0-16

Description

The query expects that as pointers are made they are assigned to variables, and assumes that pointers into arrays always use ArrayExpr (eg x[y]). It also allows dereferencing or indexing past 1 of an array -- its OK to make a pointer to 1 past the array, but dereferencing is not defined.

Example

void example_function() {
  int x[10];

  int *p1 = &x[12]; // NON_COMPLIANT
  f(p1);

  int *p2 = x + 12; // NON_COMPLIANT[FALSE_NEGATIVE]

  f(&x[12]); // NON_COMPLIANT[FALSE_NEGATIVE]

  int *p3 = &x[10]; // COMPLIANT
  *p3; // NON_COMPLIANT[FALSE_NEGATIVE]
  x[10]; // NON_COMPLIANT[FALSE_NEGATIVE] - at least for MISRA-C
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    Triaged

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy