From 11a2acc387b274d2323104272e585a7059b96f4f Mon Sep 17 00:00:00 2001 From: Mahircan Gul Date: Fri, 15 Jul 2016 16:44:32 +0200 Subject: Replace pointer arithmetic on loop-condition for parsing CPU map -Appearantly, a newline character is appended to the end of CPU mapping string. It seems like this was not the case with old versions of liblitmus and in order not to break the intended behaviour of code, newline appended to CPU mapping string is simply ignored -Pointer arithmetic for parsing CPU mapping is done within loop body to prevent "array subscript is below array bounds" warning prompted by gcc-6.1.1 -Fix indentation and whitespaces --- src/migration.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/migration.c b/src/migration.c index a259c48..c1e5a80 100644 --- a/src/migration.c +++ b/src/migration.c @@ -57,6 +57,11 @@ static int read_mapping(int idx, const char* which, cpu_set_t** set, size_t *sz) goto out; len = strnlen(buf, sizeof(buf)); + /* if there is, omit newline at the end of string */ + if (buf[len-1] == '\n') { + buf[len-1] = '\0'; + len -= 1; + } nbits = 32*(len/9) + 4*(len%9); /* compute bits, accounting for commas */ *set = CPU_ALLOC(nbits); @@ -64,12 +69,15 @@ static int read_mapping(int idx, const char* which, cpu_set_t** set, size_t *sz) CPU_ZERO_S(*sz, *set); /* process LSB chunks first (at the end of the str) and move backward */ - chunk_str = buf + len - 9; + chunk_str = buf + len; i = 0; - do - { + do { unsigned long chunk; - if(chunk_str < buf) + /* since strtoul stops processing the string with occurrence of + first non-digit character, it is necessary to read 8-bytes + on first iteration for ignoring the leading comma*/ + chunk_str -= (9 + ((i == 0) ? -1 : 0)); + if (chunk_str < buf) chunk_str = buf; /* when MSB mask is less than 8 chars */ chunk = strtoul(chunk_str, NULL, 16); while (chunk) { @@ -78,9 +86,8 @@ static int read_mapping(int idx, const char* which, cpu_set_t** set, size_t *sz) CPU_SET_S(x, *sz, *set); chunk &= ~(1ul << j); } - chunk_str -= 9; i += 1; - } while(chunk_str >= buf - 8); + } while (chunk_str > buf); ret = 0; -- cgit v1.2.2