scionproto / scion

SCION Internet Architecture
https://scion.org
Apache License 2.0
381 stars 160 forks source link

pkg/slayers: simplify Decoded.Reverse #4498

Closed jcp19 closed 6 months ago

jcp19 commented 6 months ago

Decode.Reverse seems to have a loop where one isn't needed. For the loop that I changed, there is at most one iteration (the original value of i is 0 and the original value of j is at most 2; after one iteration, the loop condition will always be broken). Besides being harder to read, it is also harder to reason about and this complicates our proofs and maintenance in the VerifiedSCION project.

To preserve the behaviour that stores on slices and arrays are only performed when s.NumINF is at least 2, I added an if statement. If you prefer, we can drop that as well.

matzf commented 6 months ago

This change is Reviewable