diff options
Diffstat (limited to 'libbb/procps.c')
-rw-r--r-- | libbb/procps.c | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/libbb/procps.c b/libbb/procps.c index 39ddd2c12..dbae46e33 100644 --- a/libbb/procps.c +++ b/libbb/procps.c | |||
@@ -128,10 +128,11 @@ static unsigned long fast_strtoul_16(char **endptr) | |||
128 | char *str = *endptr; | 128 | char *str = *endptr; |
129 | unsigned long n = 0; | 129 | unsigned long n = 0; |
130 | 130 | ||
131 | while ((c = *str++) != ' ') { | 131 | /* Need to stop on both ' ' and '\n' */ |
132 | while ((c = *str++) > ' ') { | ||
132 | c = ((c|0x20) - '0'); | 133 | c = ((c|0x20) - '0'); |
133 | if (c > 9) | 134 | if (c > 9) |
134 | // c = c + '0' - 'a' + 10: | 135 | /* c = c + '0' - 'a' + 10: */ |
135 | c = c - ('a' - '0' - 10); | 136 | c = c - ('a' - '0' - 10); |
136 | n = n*16 + c; | 137 | n = n*16 + c; |
137 | } | 138 | } |
@@ -144,11 +145,12 @@ static unsigned long fast_strtoul_16(char **endptr) | |||
144 | /* We cut a lot of corners here for speed */ | 145 | /* We cut a lot of corners here for speed */ |
145 | static unsigned long fast_strtoul_10(char **endptr) | 146 | static unsigned long fast_strtoul_10(char **endptr) |
146 | { | 147 | { |
147 | char c; | 148 | unsigned char c; |
148 | char *str = *endptr; | 149 | char *str = *endptr; |
149 | unsigned long n = *str - '0'; | 150 | unsigned long n = *str - '0'; |
150 | 151 | ||
151 | while ((c = *++str) != ' ') | 152 | /* Need to stop on both ' ' and '\n' */ |
153 | while ((c = *++str) > ' ') | ||
152 | n = n*10 + (c - '0'); | 154 | n = n*10 + (c - '0'); |
153 | 155 | ||
154 | *endptr = str + 1; /* We skip trailing space! */ | 156 | *endptr = str + 1; /* We skip trailing space! */ |
@@ -199,7 +201,7 @@ int FAST_FUNC procps_read_smaps(pid_t pid, struct smaprec *total, | |||
199 | memset(&currec, 0, sizeof(currec)); | 201 | memset(&currec, 0, sizeof(currec)); |
200 | while (fgets(buf, PROCPS_BUFSIZE, file)) { | 202 | while (fgets(buf, PROCPS_BUFSIZE, file)) { |
201 | // Each mapping datum has this form: | 203 | // Each mapping datum has this form: |
202 | // f7d29000-f7d39000 rw-s ADR M:m OFS FILE | 204 | // f7d29000-f7d39000 rw-s FILEOFS M:m INODE FILENAME |
203 | // Size: nnn kB | 205 | // Size: nnn kB |
204 | // Rss: nnn kB | 206 | // Rss: nnn kB |
205 | // ..... | 207 | // ..... |
@@ -224,7 +226,7 @@ int FAST_FUNC procps_read_smaps(pid_t pid, struct smaprec *total, | |||
224 | tp = strchr(buf, '-'); | 226 | tp = strchr(buf, '-'); |
225 | if (tp) { | 227 | if (tp) { |
226 | // We reached next mapping - the line of this form: | 228 | // We reached next mapping - the line of this form: |
227 | // f7d29000-f7d39000 rw-s ADR M:m OFS FILE | 229 | // f7d29000-f7d39000 rw-s FILEOFS M:m INODE FILENAME |
228 | 230 | ||
229 | if (cb) { | 231 | if (cb) { |
230 | /* If we have a previous record, there's nothing more | 232 | /* If we have a previous record, there's nothing more |
@@ -243,7 +245,7 @@ int FAST_FUNC procps_read_smaps(pid_t pid, struct smaprec *total, | |||
243 | 245 | ||
244 | strncpy(currec.smap_mode, tp, sizeof(currec.smap_mode)-1); | 246 | strncpy(currec.smap_mode, tp, sizeof(currec.smap_mode)-1); |
245 | 247 | ||
246 | // skipping "rw-s ADR M:m OFS " | 248 | // skipping "rw-s FILEOFS M:m INODE " |
247 | tp = skip_whitespace(skip_fields(tp, 4)); | 249 | tp = skip_whitespace(skip_fields(tp, 4)); |
248 | // filter out /dev/something (something != zero) | 250 | // filter out /dev/something (something != zero) |
249 | if (strncmp(tp, "/dev/", 5) != 0 || strcmp(tp, "/dev/zero\n") == 0) { | 251 | if (strncmp(tp, "/dev/", 5) != 0 || strcmp(tp, "/dev/zero\n") == 0) { |