[Devel] [PATCH 08/10] get_num_cpu(): got rid of hardcoded string length

Igor Podlesny openvz at poige.ru
Mon May 6 23:42:10 PDT 2013


---
 src/lib/util.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/lib/util.c b/src/lib/util.c
index 2345d1f..66c78df 100644
--- a/src/lib/util.c
+++ b/src/lib/util.c
@@ -547,7 +547,8 @@ int get_num_cpu(void)
 		return 1;
 	}
 	while (fgets(str, sizeof(str), fd)) {
-		if (!strncmp(str, "processor", 9))
+		char const proc_ptrn[] = "processor";
+		if (!strncmp(str, proc_ptrn, sizeof(proc_ptrn) - 1))
 			ncpu++;
 	}
 	fclose(fd);
-- 
1.7.9.5




More information about the Devel mailing list