Skip to content

STR34-C: Do not consider integer type aliases in templates #576

Closed
@lcartey

Description

@lcartey

Affected rules

  • STR34-C

Description

This query identifies conversions from signed chars to larger signed integers. This is a C rule, however it is part of the collection of C rules that can be applied to C++. In the case of C++, we observe potential false positives where such conversions happen in a template.

This is because the query usually only reports cases where char or signed char are directly referenced. This is to avoid flagging code using typedefs of char which are intended to be used integer types, not char types. For example, it's common for int8_t to be typedef'd to char, and the rule wouldn't apply in this case because there's no developer confusion over the conversion. However, in template instantiations we see the fully resolved types, which means we would flag conversions if they occur in the template.

Example

template <typename S, typename T> S get(T t) {
   S s = t;  // FALSE_POSITIVE - for instantiation
  return s;
}

void test(int8_t c) {
  int32_t a = c; // COMPLIANT - conversion occurs, but type is not char
  int32_t b = get<int32_t, int8_t>(c); // triggers a false positive in the template
}

Metadata

Metadata

Assignees

Labels

Difficulty-MediumA false positive or false negative report which is expected to take 1-5 days effort to addressImpact-MediumStandard-CERT-Cfalse positive/false negativeAn issue related to observed false positives or false negatives.user-reportIssue reported by an end user of CodeQL Coding Standards

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions