From 7aadd1cb3034828b3b9bced5b38b6bd00f0b7fc2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rafa=C5=82=20Mi=C5=82ecki?= Date: Thu, 8 Feb 2018 14:50:19 +0100 Subject: [PATCH] mount: improve handling mounts table size MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This is static array with a size set to MAX_MOUNTED. Old code: 1) Was never using the last table entry/row 2) Was logging the same message for every mount entry above limit This fixes off-by-one, moves limit check to the proper place and uses "break" when needed. Signed-off-by: Rafał Miłecki --- mount.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/mount.c b/mount.c index db77f10..9cb1a43 100644 --- a/mount.c +++ b/mount.c @@ -626,6 +626,12 @@ static void mount_check_mount_list(void) while(fgets(tmp, 256, fp) != NULL) { char *t, *t2; + + if (mounted_count + 1 > MAX_MOUNTED) { + log_printf("found more than %d mounts \n", MAX_MOUNTED); + break; + } + t = strstr(tmp, " "); if(t) { @@ -651,10 +657,8 @@ static void mount_check_mount_list(void) mounted[mounted_count][0], mounted[mounted_count][1], mounted[mounted_count][2]);*/ - if(mounted_count < MAX_MOUNTED - 1) - mounted_count++; - else - log_printf("found more than %d mounts \n", MAX_MOUNTED); + + mounted_count++; } fclose(fp); } -- 2.25.1