Subject: fix segfault when reading a file with non cpu_idle traces From: Daniel Lezcano The code is not designed to handle traces not coming from cpu_idle sub systems. Ignoring these lines. Signed-off-by: Daniel Lezcano --- idlestat.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) Index: idlestat/idlestat.c =================================================================== --- idlestat.orig/idlestat.c +++ idlestat/idlestat.c @@ -276,8 +276,7 @@ static struct cpuidle_datas *load_data(c FILE *f; unsigned int state = 0, cpu = 0, nrcpus= 0; double time, begin, end; - size_t count; - + size_t count, start; struct cpuidle_datas *datas; f = fopen(path, "r"); @@ -302,13 +301,18 @@ static struct cpuidle_datas *load_data(c datas->nrcpus = nrcpus; - for (; fgets(buffer, BUFSIZE, f); count++) { + for (start = 1; fgets(buffer, BUFSIZE, f); count++) { + + if (!strstr(buffer, "cpu_idle")) + continue; sscanf(buffer, "%*[^]]] %lf:%*[^=]=%u%*[^=]=%d", &time, &state, &cpu); - if (count == 2) + if (start) { begin = time; + start = 0; + } end = time; store_data(time, state, cpu, datas, count);