Skip to content

Comparison of integer expression of different signedness. #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
TylerBird opened this issue Jan 5, 2021 · 0 comments · Fixed by #7
Closed

Comparison of integer expression of different signedness. #6

TylerBird opened this issue Jan 5, 2021 · 0 comments · Fixed by #7

Comments

@TylerBird
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant