This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

C2000 Lack of integer truncation warning

Other Parts Discussed in Thread: MOTORWARE

A developer I work with found a bug in the TI supplied gpio.c driver, where it returned a uint16_t, instead of the the uint32_t register that it was returning

The bug in the driver has been reported, but I was curious why the compiler did not provide a warning for integer truncation. A warning would have made this issue easy to spot.

Device: TMS320F28069m

Compiler: C2000 TI v6.4.4

Motorware version: 1.01.00.14

File: C:\ti\motorware\motorware_1_01_00_14\sw\drivers\gpio\src\32b\f28x\f2806x\gpio.c

uint16_t GPIO_getPortData(GPIO_Handle gpioHandle, const GPIO_Port_e gpioPort)
{
  GPIO_Obj *gpio = (GPIO_Obj *)gpioHandle;

  if(gpioPort == GPIO_Port_A)
    {
        return (gpio->GPADAT);
    }
  else if(gpioPort == GPIO_Port_B)
    {
        return (gpio->GPBDAT);
    }

  return (NULL);

} // end of GPIO_getPortData() function

However...

...
volatile uint32_t GPADAT;          //!< GPIO A Data Register
...

  • With regard to automatic checks for errors in your source, the TI compiler is not your best choice.  A web search on static program analysis tools shows many tools worth considering.  Their business is static program analysis.  The TI compiler will never be as good.

    That said, you could build this source with the options --check_misra=10.1 --verbose_diagnostics and get a diagnostic similar to this ...

    "file.c", line 8: warning: (MISRA-C:2004 10.1/R) The value of an expression of
              integer type shall not be implicitly converted to a different
              underlying type if the expression is not constant and is a return
              expression
            return u32;
                   ^
    

    Thanks and regards,

    -George