Hi Rafael,
>
>> - line 147: state++;
>> Can you garantee that npstates will be always less then
>> NSTATES? Probably we need to check that we are not going
>> over array bounds?
>
> It *should* be, but I'm adding a check anyway.
>
>
If it would never happen, just ASSERT() seems enough to me.
If it can, then with code below we still can corrupt memory
besides pstate_info[].
111 state = pstate_info;
...
132 for (token = strtok(s, ":"), s = NULL; NULL != token;
133 token = strtok(NULL, ":")) {
134
135 state->speed = HZ2MHZ(atoll(token));
136
137 if (state->speed > max_cpufreq)
138 max_cpufreq = state->speed;
139
140 state->total_time = (uint64_t)0;
141
142 /*
143 * NSTATES should be large enough, but you never know..
144 */
145 if (npstates < NSTATES)
146 npstates++;
147
148 state++;
149 }
Something like that, would probably do:
for (token = strtok(s, ":");
NULL != token && npstates < NSTATES;
token = strtok(NULL, ":")) {
....
npstates++;
state++;
}
if (token != NULL) {
/*print warning that we exceeded NPSTATES?*/
}
Thanks
Konstantin
> ------------------------------------------------------------------------
>
> _