Make overflow checks more readable
Signed-off-by: David Horstmann <david.horstmann@arm.com>
diff --git a/library/oid.c b/library/oid.c
index fb4caad..e36caf2 100644
--- a/library/oid.c
+++ b/library/oid.c
@@ -806,7 +806,7 @@
while (i < oid->len && ((oid->p[i] & 0x80) != 0)) {
/* Prevent overflow in value. */
- if (((value << 7) >> 7) != value) {
+ if (value > (UINT_MAX >> 7)) {
return MBEDTLS_ERR_OID_BUF_TOO_SMALL;
}
@@ -835,7 +835,7 @@
value = 0;
for (; i < oid->len; i++) {
/* Prevent overflow in value. */
- if (((value << 7) >> 7) != value) {
+ if (value > (UINT_MAX >> 7)) {
return MBEDTLS_ERR_OID_BUF_TOO_SMALL;
}
if ((value == 0) && ((oid->p[i]) == 0x80)) {