diff options
author | Mahircan Gul <mahircg@mpi-sws.org> | 2016-07-15 10:44:32 -0400 |
---|---|---|
committer | Bjoern Brandenburg <bbb@mpi-sws.org> | 2016-07-18 10:45:57 -0400 |
commit | 11a2acc387b274d2323104272e585a7059b96f4f (patch) | |
tree | be47f7a1230dc870a975c7068d48ed1d3ec9ddf9 | |
parent | 3e9e2dc67655e4e681dc01f3b35916407eda5ce5 (diff) |
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
-rw-r--r-- | src/migration.c | 19 |
1 files 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) | |||
57 | goto out; | 57 | goto out; |
58 | 58 | ||
59 | len = strnlen(buf, sizeof(buf)); | 59 | len = strnlen(buf, sizeof(buf)); |
60 | /* if there is, omit newline at the end of string */ | ||
61 | if (buf[len-1] == '\n') { | ||
62 | buf[len-1] = '\0'; | ||
63 | len -= 1; | ||
64 | } | ||
60 | nbits = 32*(len/9) + 4*(len%9); /* compute bits, accounting for commas */ | 65 | nbits = 32*(len/9) + 4*(len%9); /* compute bits, accounting for commas */ |
61 | 66 | ||
62 | *set = CPU_ALLOC(nbits); | 67 | *set = CPU_ALLOC(nbits); |
@@ -64,12 +69,15 @@ static int read_mapping(int idx, const char* which, cpu_set_t** set, size_t *sz) | |||
64 | CPU_ZERO_S(*sz, *set); | 69 | CPU_ZERO_S(*sz, *set); |
65 | 70 | ||
66 | /* process LSB chunks first (at the end of the str) and move backward */ | 71 | /* process LSB chunks first (at the end of the str) and move backward */ |
67 | chunk_str = buf + len - 9; | 72 | chunk_str = buf + len; |
68 | i = 0; | 73 | i = 0; |
69 | do | 74 | do { |
70 | { | ||
71 | unsigned long chunk; | 75 | unsigned long chunk; |
72 | if(chunk_str < buf) | 76 | /* since strtoul stops processing the string with occurrence of |
77 | first non-digit character, it is necessary to read 8-bytes | ||
78 | on first iteration for ignoring the leading comma*/ | ||
79 | chunk_str -= (9 + ((i == 0) ? -1 : 0)); | ||
80 | if (chunk_str < buf) | ||
73 | chunk_str = buf; /* when MSB mask is less than 8 chars */ | 81 | chunk_str = buf; /* when MSB mask is less than 8 chars */ |
74 | chunk = strtoul(chunk_str, NULL, 16); | 82 | chunk = strtoul(chunk_str, NULL, 16); |
75 | while (chunk) { | 83 | while (chunk) { |
@@ -78,9 +86,8 @@ static int read_mapping(int idx, const char* which, cpu_set_t** set, size_t *sz) | |||
78 | CPU_SET_S(x, *sz, *set); | 86 | CPU_SET_S(x, *sz, *set); |
79 | chunk &= ~(1ul << j); | 87 | chunk &= ~(1ul << j); |
80 | } | 88 | } |
81 | chunk_str -= 9; | ||
82 | i += 1; | 89 | i += 1; |
83 | } while(chunk_str >= buf - 8); | 90 | } while (chunk_str > buf); |
84 | 91 | ||
85 | ret = 0; | 92 | ret = 0; |
86 | 93 | ||