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-8-7: Flags functions that are called in only one unit, different than the unit it is defined in #864

Open
picardb opened this issue Mar 5, 2025 · 1 comment · May be fixed by #868
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. Impact-Medium user-report Issue reported by an end user of CodeQL Coding Standards

Comments

@picardb
Copy link

picardb commented Mar 5, 2025

Affected rules

  • RULE-8-7

Description

The query flags all functions that are called in only one unit, even if that unit is not the one where the function is defined. Technically, if we understand the term "referenced" as "called", this would indeed be a violation of the rule. But according to a MISRA official in this forum post, "referenced" should also include the definition of the function.

Example

Example taken from the forum post mentioned above. Here, bar() is flagged as a violation of the rule even if it is called from main.c.

/* foo.h*/
#ifndef FOO_H
#define FOO_H

extern void foo(void);
extern void bar(void);

#endif

/* foo.c*/
#include "foo.h"

void foo(void)
{
}

void bar(void)
{
  foo();
}

/* main.c*/
#include "foo.h"

int main(void)
{
  bar();
  return 0;
}

@picardb picardb added the false positive/false negative An issue related to observed false positives or false negatives. label Mar 5, 2025
@lcartey lcartey moved this from Reported to Triaged in Coding Standards Public Development Board Mar 9, 2025
@lcartey lcartey added Difficulty-Medium A false positive or false negative report which is expected to take 1-5 days effort to address Impact-Medium labels Mar 9, 2025
@lcartey
Copy link
Collaborator

lcartey commented Mar 10, 2025

@picardb Thanks for the report! I agree that we shouldn't flag cases where the reference and the definition occur in different translation units.

@lcartey lcartey moved this from Triaged to In Progress in Coding Standards Public Development Board Mar 10, 2025
@lcartey lcartey moved this from In Progress to Ready for review in Coding Standards Public Development Board Mar 10, 2025
@lcartey lcartey added the user-report Issue reported by an end user of CodeQL Coding Standards label Mar 10, 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. Impact-Medium user-report Issue reported by an end user of CodeQL Coding Standards
Projects
Status: Ready for review
2 participants