Fixing some NULL pointer issues in the

EXPERIMENTAL_HIGH_PRECISION_MATH_Q3MAP2_FIXES code path.
Adding extra checks for NULL in the following functions:
- FreeWinding()
- FreeWindingAccu()
- CopyWinding()
- CopyWindingAccuToNormal()
If a NULL winding is passed to any of these functions, a graceful error will
result (as opposed to a segfault).


git-svn-id: svn://svn.icculus.org/gtkradiant/GtkRadiant/branches/Rambetter-math-fix-experiments@391 8a3a26a2-13c4-0310-b231-cf6edde360e5
This commit is contained in:
rambetter 2010-12-31 03:21:01 +00:00
parent 883e3164be
commit 01ac3e0a46
2 changed files with 10 additions and 2 deletions

View file

@ -108,6 +108,8 @@ FreeWinding
*/
void FreeWinding (winding_t *w)
{
if (!w) Error("FreeWinding: winding is NULL");
if (*(unsigned *)w == 0xdeaddead)
Error ("FreeWinding: freed a freed winding");
*(unsigned *)w = 0xdeaddead;
@ -124,6 +126,8 @@ FreeWindingAccu
*/
void FreeWindingAccu(winding_accu_t *w)
{
if (!w) Error("FreeWindingAccu: winding is NULL");
if (*((unsigned *) w) == 0xdeaddead)
Error("FreeWindingAccu: freed a freed winding");
*((unsigned *) w) = 0xdeaddead;
@ -453,6 +457,8 @@ winding_t *CopyWinding (winding_t *w)
int size;
winding_t *c;
if (!w) Error("CopyWinding: winding is NULL");
c = AllocWinding (w->numpoints);
size = (int)((size_t)((winding_t *)0)->p[w->numpoints]);
memcpy (c, w, size);
@ -469,6 +475,8 @@ winding_t *CopyWindingAccuToNormal(winding_accu_t *w)
int i;
winding_t *c;
if (!w) Error("CopyWindingAccuToNormal: winding is NULL");
c = AllocWinding(w->numpoints);
c->numpoints = w->numpoints;
for (i = 0; i < c->numpoints; i++)

View file

@ -462,8 +462,8 @@ qboolean CreateBrushWindings( brush_t *brush )
/* set side winding */
#if EXPERIMENTAL_HIGH_PRECISION_MATH_Q3MAP2_FIXES
side->winding = CopyWindingAccuToNormal(w);
FreeWindingAccu(w);
side->winding = (w ? CopyWindingAccuToNormal(w) : NULL);
if (w) FreeWindingAccu(w);
#else
side->winding = w;
#endif