From a3f61d068008457e19c8325a5131cc37460d4348 Mon Sep 17 00:00:00 2001 From: baldurk Date: Wed, 20 Jul 2016 16:58:52 +0200 Subject: [PATCH] [Coverity] Add paranoia protection around left-shift in double printing --- renderdoc/serialise/grisu2.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/renderdoc/serialise/grisu2.cpp b/renderdoc/serialise/grisu2.cpp index 944af541c..376d62be0 100644 --- a/renderdoc/serialise/grisu2.cpp +++ b/renderdoc/serialise/grisu2.cpp @@ -264,6 +264,12 @@ int grisu2(uint64_t mantissa, int exponent, char digits[18], int &kout) upper.mantissa <<= 1; upper.exp--; } + + // for valid floats shift operation will always be non-negative, but just to be paranoid let's + // make sure that it is. This will produce incorrect results but garbage-in, garbage-out. + if(lower.exp < upper.exp) + lower.exp = upper.exp; + // lower needs to be the same exponent as upper so we can calculate delta by upper-lower, so // it is not normalised, but shifted to upper's exponent lower.mantissa <<= (lower.exp - upper.exp);