adafruit / adafruit/TinyDHT

readHumidity() can never return BAD_HUM

Open
#9 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
45
Forks
19
PR merge metrics
No merged PRs in 30d

Description

In practice, comparing readHumidity() with BAD_HUM (BAD_HUM = -1) may work, but readHumidity() is factually returning an unsigned int (uint8_t) which can never become -1.
Any (uint8_t) variable supposed to store the result of readHumidity(), when initialized with BAD_HUM, generates a **compiler warning**.
I would suggest to fix this by changing the return value of readTemperature() to type int16_t.

readTemperature() is OK because it returns a signed int (int16_t), allowing to factually return -999 in case of BAD_TEMP.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start at the readHumidity() declaration and implementation, then inspect BAD_HUM and the corresponding readTemperature() return type. Resolve the issue's requested return-type change for humidity and verify that BAD_HUM can be represented without a compiler warning.

Written by the indexing model from the issue text.

Assessment

Tech stack
arduino, cpp
Domain
embedded-iot
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.