Skip to content

Commit 06b53c7

Browse files
committed
per review (Type casts are always dangerous)
1 parent 1e50936 commit 06b53c7

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/lmic/lmic.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -721,11 +721,17 @@ static CONST_TABLE(u1_t, macCmdSize)[] = {
721721
};
722722

723723
static u1_t getMacCmdSize(u1_t macCmd) {
724-
if (macCmd < 2)
725-
return 0;
726-
if (((size_t)(macCmd - 2)) >= LENOF_TABLE(macCmdSize))
727-
return 0;
728-
return TABLE_GET_U1(macCmdSize, macCmd - 2);
724+
if (macCmd >= 2) {
725+
const unsigned macCmdMinus2 = macCmd - 2u;
726+
if (macCmdMinus2 < LENOF_TABLE(macCmdSize)) {
727+
// macCmd in table, fetch it's size.
728+
return TABLE_GET_U1(macCmdSize, macCmdMinus2);
729+
}
730+
}
731+
// macCmd too small or too large: return zero. Zero is
732+
// never a legal command size, so it signals an error
733+
// to the caller.
734+
return 0;
729735
}
730736

731737
static bit_t

0 commit comments

Comments
 (0)