Skip to content

Commit ceeccce

Browse files
committed
sns: off-by-one errors
mod10 and mod100 should be inclusive (oops) recover from post vs. pre increment mixup offset when formatting, store as-is
1 parent fe08a66 commit ceeccce

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

code/espurna/sensor.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -387,10 +387,10 @@ constexpr
387387
#endif
388388
std::array<char, 3> format_slot_number_impl(unsigned char number) {
389389
return std::array<char, 3>{
390-
number > 100
390+
number >= 100
391391
? dec_digit2char(number / 100)
392392
: '0',
393-
number > 10
393+
number >= 10
394394
? dec_digit2char((number / 10) % 10)
395395
: '0',
396396
number
@@ -1304,11 +1304,11 @@ unsigned char types_count[MAGNITUDE_MAX]{};
13041304
} // namespace internal
13051305

13061306
unsigned char instance_count_add(unsigned char id) {
1307-
return ++internal::instance_count[id];
1307+
return internal::instance_count[id]++;
13081308
}
13091309

13101310
unsigned char types_count_add(unsigned char type) {
1311-
return ++internal::types_count[type];
1311+
return internal::types_count[type]++;
13121312
}
13131313

13141314
unsigned char types_count(unsigned char type) {
@@ -1350,9 +1350,9 @@ String format_slot(const Magnitude& magnitude) {
13501350
const auto slot = make_slot(
13511351
SlotValues{
13521352
.id = magnitude.sensor->id(),
1353-
.index = magnitude.slot_global,
1353+
.index = static_cast<unsigned char>(magnitude.slot_global + 1),
13541354
.type = magnitude.type,
1355-
.slot = magnitude.slot,
1355+
.slot = static_cast<unsigned char>(magnitude.slot + 1),
13561356
});
13571357

13581358
const auto out = StringView(slot.data(), slot.size());

0 commit comments

Comments
 (0)