diff options
author | Sebastian Leske <sebastian.leske@sleske.name> | 2017-09-25 08:37:56 +0200 |
---|---|---|
committer | Sebastian Leske <sebastian.leske@sleske.name> | 2017-10-12 17:01:25 +0200 |
commit | 02e06262fa11a6b327d2dd747e87249059936ad9 (patch) | |
tree | 9f712ef4d3d319d2296b7576d3d1052815c0f23b | |
parent | a3435121850201dc163c5f55153ea4bc9d91e179 (diff) | |
download | navit-02e06262fa11a6b327d2dd747e87249059936ad9.tar.gz |
Fix:core:Reduce POST_SHIFT to avoid int overflow
During coordinate transformation, map coordinates are multiplied by
POST_SHIFT (and later divided again). This can cause integer overflows
during the multiplication with the transformation matrix in
transform_rotate, when a map contains large objects and is zoomed in all
the way.
Reduce POST_SHIFT to avoid this.
-rw-r--r-- | navit/transform.c | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/navit/transform.c b/navit/transform.c index 2f64ced1b..1c6eeae67 100644 --- a/navit/transform.c +++ b/navit/transform.c @@ -34,7 +34,29 @@ #include "projection.h" #include "point.h" -#define POST_SHIFT 8 +/** @file + * + * Coordinate transformations and projections. + */ + +/** + * @brief Bitshift to apply during coordinate transformation. + * + * This bitshift is applied (left shift) during coordinate transformation (and later reversed). + * The transformation is performed with integer arithmetic, and this shift reduces rounding + * errors when converting floating point numbers to integers, particularly because some input + * values are fairly small (for example, the entries in the transformation matrix, <tt>struct + * transformation</tt>). + * + * This works because the transformations involve only multiplications, so the shift can be + * applied to one factor and removed from the result. + * + * The value is a compromise; if it is too small, rounding errors increase, if it is too large, + * signed integer calculations will overflow at high zoom levels (which is undefined behavior). + * + * @see transformation + */ +#define POST_SHIFT 5 /** * @brief The parameters needed to transform a map for display. |