Attention is currently required from: Edward O'Callaghan, Angel Pons, Anastasia Klimchuk, Nikolai Artemiev, Sergii Dmytruk. Nico Huber has posted comments on this change. ( https://review.coreboot.org/c/flashrom/+/58481 )
Change subject: libflashrom,writeprotect: add flashrom_wp_get_available_ranges() ......................................................................
Patch Set 10:
(2 comments)
File writeprotect.c:
https://review.coreboot.org/c/flashrom/+/58481/comment/8c9d3160_7ece42e9 PS10, Line 271: ranges[++last] = ranges[i];
I don't understand how it works :(( this assignment... […]
In the first iteration (last == 0, i == 0), it would compare the same element, hence `duplicate` would be `true` and this line would be skipped.
In further iterations, `last` would at least be one less than `i`, hence it would potentially overwrite duplicates (at `last + 1`) with later elements at `i`.
It's hard to read, indeed. Starting the loop at `i == 1` might make things easier.
And there is at least one (theoretical?) case where the code fails, see below.
https://review.coreboot.org/c/flashrom/+/58481/comment/dfc5b99e_92f14bdb PS10, Line 274: *count = last + 1; If `*count` was 0 initially, i.e. an empty list, this would set it to `1`.