dmitrystu / libusb_stm32

Lightweight USB device Stack for STM32 microcontrollers
Apache License 2.0
721 stars 165 forks source link

Warning in usbd_stm32f103_devfs.c #99

Closed GrantMTG closed 3 years ago

GrantMTG commented 3 years ago

I don't know why this warning never showed up before during my builds, but thought people should be aware anyway:

src/usbd_stm32f103_devfs.c:368:17: warning: 'tmp' may be used uninitialized in this function [-Wmaybe-uninitialized]

static uint16_t pma_read (uint8_t *buf, uint16_t blen, pma_rec *rx) {
    uint16_t tmp;
    uint16_t *pma = PMA(rx->addr);
    uint16_t rxcnt = rx->cnt & 0x03FF;
    rx->cnt &= ~0x3FF;
    for(int idx = 0; idx < rxcnt; idx++) {
        if ((idx & 0x01) == 0) {
            tmp = *pma;
            pma += PMA_STEP;
        }
        if (idx < blen) {
            buf[idx] = tmp & 0xFF;
            tmp >>= 8;
        } else {
            return blen;
        }
    }
    return rxcnt;
}
GrantMTG commented 3 years ago

BTW, I just thought I should mention that, curiously, this warning occurs with STM32CubeIDE with optimizations turned on. Both Keil and STM32CubeIDE say it's OK with optimizations off. I have not tried the Keil optimizations yet.

dmitrystu commented 3 years ago

I see no problems with GCC. Some compilers may consider that this variable is uninitialized, but this is not true. It will be initialized on the first loop iteration.

GrantMTG commented 3 years ago

Agreed. Please to close or delete.