From 0ea1528dfc7375ce0cccbd4b64b3f533c8662ccb Mon Sep 17 00:00:00 2001 From: illiliti Date: Wed, 26 May 2021 14:23:24 +0300 Subject: [PATCH] udev_device.c: simplify bounds checking --- udev_device.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/udev_device.c b/udev_device.c index dfc4431..593e034 100644 --- a/udev_device.c +++ b/udev_device.c @@ -357,15 +357,17 @@ static void make_bit(unsigned long *arr, int cnt, const char *str) return; } - for (i = 0, len = strlen(str); i < cnt && len > 0; len--) { + for (i = 0, len = strlen(str); len > 0; len--) { if (str[len] == ' ') { arr[i++] = strtoul(str + len + 1, NULL, 16); } + + if (i == cnt) { + return; + } } - if (i < cnt) { - arr[i] = strtoul(str, NULL, 16); - } + arr[i] = strtoul(str, NULL, 16); } static int test_bit(unsigned long *arr, unsigned long bit)