From a594ae703d14acc045e9eaedc8615ea981968da6 Mon Sep 17 00:00:00 2001 From: Alexander Boettcher Date: Wed, 18 Feb 2015 12:06:40 +0100 Subject: [PATCH] base: fix location_of_index affinity calculation Take care that ypos parameter is smaller than height(). If it is not - wrap around. Issue #1412. --- repos/base/include/base/affinity.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/repos/base/include/base/affinity.h b/repos/base/include/base/affinity.h index 8e05ff900..2e1794104 100644 --- a/repos/base/include/base/affinity.h +++ b/repos/base/include/base/affinity.h @@ -75,7 +75,13 @@ namespace Genode { } /** - * Return location of a single CPU of specified index + * Return the location of the Nth CPU within the affinity + * space + * + * This function returns a valid location even if the index + * is larger than the number of CPUs in the space. In this + * case, the x and y coordinates are wrapped by the bounds + * of the space. */ inline Location location_of_index(int index); }; @@ -178,7 +184,7 @@ namespace Genode { Affinity::Location Affinity::Space::location_of_index(int index) { - return Location(index % _width, index / _width, 1, 1); + return Location(index % _width, (index / _width) % _height, 1, 1); } }