Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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 opened this issue Jan 16, 2025 · 0 comments
Labels
Difficulty-Medium A false positive or false negative report which is expected to take 1-5 days effort to address false positive/false negative An issue related to observed false positives or false negatives. false-negative An issue representing a false negative report. Impact-Medium Standard-AUTOSAR Standard-MISRA-C

Comments

@MichaelRFairhurst
Copy link
Contributor

MichaelRFairhurst commented Jan 16, 2025

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
}
@MichaelRFairhurst MichaelRFairhurst added Difficulty-Medium A false positive or false negative report which is expected to take 1-5 days effort to address false positive/false negative An issue related to observed false positives or false negatives. false-negative An issue representing a false negative report. Impact-Medium Standard-AUTOSAR Standard-MISRA-C labels Jan 16, 2025
@lcartey lcartey moved this from Reported to Triaged in Coding Standards Public Development Board Jan 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Difficulty-Medium A false positive or false negative report which is expected to take 1-5 days effort to address false positive/false negative An issue related to observed false positives or false negatives. false-negative An issue representing a false negative report. Impact-Medium Standard-AUTOSAR Standard-MISRA-C
Projects
Development

No branches or pull requests

1 participant