Skip to content

Comparison of integer expression of different signedness. #6

@TylerBird

Description

@TylerBird

Subject of the issue

Getting a warning caused by comparison of different data types

Your workbench

  • STM32
  • LoRa ST (EU868
  • Wired via I2C
  • The power supply is 3V3
  • I'm using PlatformIO

Output warning:

.pio\libdeps\disco_l072cz_lrwan1\SparkFun External EEPROM Arduino Library\src\SparkFun_External_EEPROM.cpp: In member function 'void ExternalEEPROM::read(uint32_t, uint8_t*, uint16_t)':
.pio\libdeps\disco_l072cz_lrwan1\SparkFun External EEPROM Arduino Library\src\SparkFun_External_EEPROM.cpp:159:50: warning: comparison of integer expressions of different signedness: 'long unsigned int' and 'int' [-Wsign-compare]
  159 |         if (0xFFFF - (eepromLocation + received) < amtToRead) //0xFFFF - 0xFFFA < 32
      |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~

Steps to reproduce

The datatype of amtToRead can be set to uint16_t since the var is initialized with bufferSize-received where bufferSize also is a uint16_t and substracted by another value. So amtToRead could never get bigger then uint16_t

Expected behavior

In file SparkFun_External_EEPROM.cpp in line 148 change the data type from int to uint16_t.

Actual behavior

In case the amtToRead var becomes negative, there is an overflow and an unintended behavior could happen.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions