/** * @name Narrowing conversions * @description Find all narrowing conversions from a larger integer type, * such as uint32_t, to a smaller integer type, such as uint8_t. * @kind problem */ import cpp import semmle.code.cpp.ir.IR /** Holds if `i` is a narrowing conversion. */ predicate isNarrowingConversion(ConvertInstruction i) { i.getResultSize() < i.getUnary().getResultSize() } from ConvertInstruction conv, Type inputType, Type outputType where isNarrowingConversion(conv) and inputType = conv.getUnary().getResultType() and outputType = conv.getResultType() select conv, "Narrowing conversion from " + inputType + " to " + outputType + "."