From c7a02e807c5cce0bd96e390d82ed5117c994045e Mon Sep 17 00:00:00 2001 From: marius Date: Sat, 9 Jul 2011 18:47:51 +0000 Subject: Fix the definition for PCPU_NAME_LEN, which is intended to fit ("CPU %d", cpuid) where cpuid <= MAXCPU. 1. sizeof(__XSTRING(MAXCPU) + 1) is a typo: typeof(__XSTRING(...) + 1) is 'char *', so sizeof() will return the size of the pointer, not the size of the string contents. The proper expression should be 'sizeof(__XSTRING(MAXCPU)) + 1'. 2. One should not add one, but substract it: sizeof() accounts for the trailing '\0' and we have two sizeof's, so the size of one '\0' should be substracted -- this will give the maximal string buffer length for CPU with its number, no less, no more. Submitted by: rea --- sys/sys/pcpu.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sys') diff --git a/sys/sys/pcpu.h b/sys/sys/pcpu.h index 2e69f81..b25fcc8 100644 --- a/sys/sys/pcpu.h +++ b/sys/sys/pcpu.h @@ -146,7 +146,7 @@ struct rm_queue { struct rm_queue* volatile rmq_prev; }; -#define PCPU_NAME_LEN (sizeof("CPU ") + sizeof(__XSTRING(MAXCPU) + 1)) +#define PCPU_NAME_LEN (sizeof("CPU ") + sizeof(__XSTRING(MAXCPU)) - 1) /* * This structure maps out the global data that needs to be kept on a -- cgit v1.1