mem: Fix off-by-one error in checkFunctional, and simplify it
authorRobert Kovacsics <rmk35@cl.cam.ac.uk>
Fri, 13 Jul 2018 16:28:11 +0000 (17:28 +0100)
committerKovacsics Róbert <kovirobi@gmail.com>
Thu, 19 Jul 2018 13:43:35 +0000 (13:43 +0000)
commitcbfe914f885cc54a3c8763c0ed6aed8e425d6357
tree0c187b8c43cf1b2f148f509bdebcca9ecafc9357
parented427a3fcdf49a0ea0afa212c96240a04d4678d7
mem: Fix off-by-one error in checkFunctional, and simplify it

There was an off-by-one error in the isRead() case, as `val_end` and
`func_end` pointed to the last byte to write to (not one past the last
byte), and thus `*_end - *_start` was not the length of the data to
memcpy.

This was correct in the case of

    val_start >= func_start && val_end <= func_end

where `overlap_size = size`, but if it were (as the other cases
suggest) `overlap_size = val_end - val_start`, then it would also be
off by one.

Also, the isWrite() case catered for this.

I simplified the four ifs into one case which uses min/max (this is
how I spotted the inconsistency).

Change-Id: Ib5c5da084652e752f6baf1eec56b51b4f0f5c95c
Reviewed-on: https://gem5-review.googlesource.com/11750
Reviewed-by: Daniel Carvalho <odanrc@yahoo.com.br>
Reviewed-by: Nikos Nikoleris <nikos.nikoleris@arm.com>
Maintainer: Nikos Nikoleris <nikos.nikoleris@arm.com>
src/mem/packet.cc