From bd11d917c19aab91df9c2c7c721233fa73a1d1d7 Mon Sep 17 00:00:00 2001 From: Mike Erwin Date: Fri, 22 Jul 2016 20:59:31 -0400 Subject: [PATCH] fix atan2f input conditional MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Suspicious conditional found by PVS-Studio T48917 Original code (from Blender’s initial open-source commit!) looks like it’s testing inputs to atan2f, to avoid undefined function values. Passing xn=0 does *not* always evaluate to 0 though… I’m not sure if this is a coding error or was done for a desired visual result. Also changed xn==0 to xn>=0 to avoid function call in more cases. Good description and visualization of atan2f function: http://en.cppreference.com/w/c/numeric/math/atan2 --- source/blender/render/intern/source/renderdatabase.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/blender/render/intern/source/renderdatabase.c b/source/blender/render/intern/source/renderdatabase.c index d3d26011a57..76e6ca8d467 100644 --- a/source/blender/render/intern/source/renderdatabase.c +++ b/source/blender/render/intern/source/renderdatabase.c @@ -1006,7 +1006,7 @@ HaloRen *RE_inithalo(Render *re, ObjectRen *obr, Material *ma, xn= har->xs - 0.5f*re->winx*(hoco1[0]/hoco1[3]); yn= har->ys - 0.5f*re->winy*(hoco1[1]/hoco1[3]); - if (xn==0.0f || (xn==0.0f && yn==0.0f)) zn= 0.0f; + if (yn == 0.0f && xn >= 0.0f) zn = 0.0f; else zn = atan2f(yn, xn); har->sin = sinf(zn); @@ -1136,7 +1136,7 @@ HaloRen *RE_inithalo_particle(Render *re, ObjectRen *obr, DerivedMesh *dm, Mater xn= har->xs - 0.5f*re->winx*(hoco1[0]/hoco1[3]); yn= har->ys - 0.5f*re->winy*(hoco1[1]/hoco1[3]); - if (xn==0.0f || (xn==0.0f && yn==0.0f)) zn= 0.0; + if (yn == 0.0f && xn >= 0.0f) zn = 0.0f; else zn = atan2f(yn, xn); har->sin = sinf(zn);