aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/migration.c19
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