Skip to content

Commit 25a8097

Browse files
henrygabNaotoFujihiro
authored andcommitted
Fix adafruit#382: [-Wsign-compare]
comparison between signed and unsigned integer expressions Use uint32_t to store timestamp instead of int32_t. Adjust comparison to use timestamp as a zero-basis. This also avoids a bugs where a record that is added just before millis() overflows would never be removed from the list.
1 parent 847a4fe commit 25a8097

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

libraries/Bluefruit52Lib/examples/Projects/rssi_proximity/rssi_proximity_central/rssi_proximity_central.ino

+5-5
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,10 @@ BLEUuid uuid = BLEUuid(CUSTOM_UUID);
128128
/* This struct is used to track detected nodes */
129129
typedef struct node_record_s
130130
{
131-
uint8_t addr[6]; // Six byte device address
132-
int8_t rssi; // RSSI value
133-
int32_t timestamp; // Timestamp for invalidation purposes
134-
int8_t reserved; // Padding for word alignment
131+
uint8_t addr[6]; // Six byte device address
132+
int8_t rssi; // RSSI value
133+
uint32_t timestamp; // Timestamp for invalidation purposes
134+
int8_t reserved; // Padding for word alignment
135135
} node_record_t;
136136

137137
node_record_t records[ARRAY_SIZE];
@@ -530,7 +530,7 @@ int invalidateRecords(void)
530530
{
531531
if (records[i].timestamp) // Ignore zero"ed records
532532
{
533-
if (records[i].timestamp <= millis() - TIMEOUT_MS)
533+
if (millis() - records[i].timestamp >= TIMEOUT_MS)
534534
{
535535
/* Record has expired, zero it out */
536536
memset(&records[i], 0, sizeof(node_record_t));

0 commit comments

Comments
 (0)