From b44fcd6e8f661e7e795212a3b68aa171ab6e49c9 Mon Sep 17 00:00:00 2001 From: Mikael Ohlson Date: Fri, 21 May 2010 11:20:39 +0200 Subject: [PATCH] Fix for incorrect reply from sysconf(_SC_NPROCESSORS_ONLN) When calling sysconf with _SC_NPROCESSORS_ONLN, the value one (1) was returned on systems with two or more cores, since '/proc/stat' was incorrectly parsed. The function line_parser_getc (LineParser* p) read 128 characters of input for each invocation. The proper and probably aimed for behavior is to read 128 characters at the first call, then for each subsequent call only return the next buffered character until a new read is needed and only then read another 128 characters. Due to a flipped comparison between the two variables in_len and in_pos that track the number of bytes of data read into the input buffer and how much of it has been parsed, a new group of 128 characters were read at almost every call to line_parser_getc, overwriting the still unhandled bytes from the previous call to read. This caused the lines to be read to be sampled more than parsed. Change-Id: I93eec3c8c9b9f19ef798748579d0977111b5c0bb Signed-off-by: Christian Bejram --- libc/unistd/sysconf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libc/unistd/sysconf.c b/libc/unistd/sysconf.c index d3089a4a4..dedc5bc17 100644 --- a/libc/unistd/sysconf.c +++ b/libc/unistd/sysconf.c @@ -317,7 +317,7 @@ line_parser_addc( LineParser* p, int c ) static int line_parser_getc( LineParser* p ) { - if (p->in_len >= p->in_pos) { + if (p->in_pos >= p->in_len) { int ret; p->in_len = p->in_pos = 0;