Skip to content

Commit 8fc5463

Browse files
committed
Fix bug in f_enneper inbuilt isosurface function detected by static code analysis (CID 1372542-1372544).
1 parent 508f60c commit 8fc5463

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

changes.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ Changed Behaviour
5656
by directives (stuff that begins with `#`).
5757
- UV mapping of cylinder, cone and lemon primitives has been disabled again
5858
for now, due to their orientation being poorly defined.
59+
- An age-old bug in the inbuilt `f_enneper` isosurface function has been
60+
fixed; the function now results in the originally intended shape.
5961

6062
New Features
6163
------------
@@ -103,6 +105,7 @@ Reported by Coverity static code analysis:
103105

104106
- CID 986462,986463 (Wrapper object use after free)
105107
- CID 967358-967362 (Uninitialized scalar variable)
108+
- CID 1372542-1372544 (Result is not floating-point)
106109
- CID 1372618 (Uninitialized scalar variable)
107110
- CID 1372629 (Uninitialized pointer read)
108111
- CID 1372630-1372632 (Uninitialized scalar variable)

distribution/include/functions.inc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,12 @@
163163
// 2. y scale (inverse)
164164
// 3. z scale (inverse)
165165

166-
#declare f_enneper = function { internal(18) }
166+
#if (Functions_Inc_Temp < 3.8)
167+
#declare deprecated once "f_enneper was broken prior to v3.8; results will most likely differ."
168+
f_enneper = function { internal(18) }
169+
#else
170+
#declare f_enneper = function { internal(18) }
171+
#end
167172
// Parameters: x, y, z
168173
// One extra parameter required:
169174
// 1. Field strength

source/vm/fnintern.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -455,8 +455,8 @@ DBL f_enneper(FPUContext *ctx, DBL *ptr, unsigned int) // 18
455455
DBL r, r2,x2=PARAM_X*PARAM_X, y2=PARAM_Y*PARAM_Y, z2=PARAM_Z*PARAM_Z;
456456
if (fabs(PARAM_Z)<0.2)
457457
PARAM_Z=0.2;
458-
r =((y2-x2)/(2*PARAM_Z)+2*z2/9+2/3); // TODO FIXME - was this supposed to be 2.0/3.0 ??
459-
r2=((y2-x2)/(4*PARAM_Z)-(1/4)*(x2+y2+(8/9)*z2)+2/9); // TODO FIXME - was this supposed to be 1.0/4.0, 8.0/9.0 and 2.0/9.0 respectively ??
458+
r =((y2-x2)/(2*PARAM_Z)+2*z2/9+(2/3.));
459+
r2=((y2-x2)/(4*PARAM_Z)-(1/4.)*(x2+y2+(8/9.)*z2)+(2/9.));
460460
r=-( r*r*r -6*r2*r2);
461461
return( min(10., max(PARAM(0)*r,-10.)) );
462462
}

0 commit comments

Comments
 (0)