Skip to content

Commit a88ef20

Browse files
committed
fix short alloc and heap corruption for winding_accu_t and brush_t - brought about by TTimo/bspc#4
1 parent b36b3ba commit a88ef20

File tree

2 files changed

+2
-7
lines changed

2 files changed

+2
-7
lines changed

tools/quake3/common/polylib.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ winding_accu_t *AllocWindingAccu( int points ){
9494
c_peak_windings = c_active_windings;
9595
}
9696
}
97-
s = sizeof( vec_accu_t ) * 3 * points + sizeof( int );
97+
s = sizeof(*w) + (points > 4 ? sizeof(vec3_accu_t) * (points - 4) : 0);
9898
w = safe_malloc( s );
9999
memset( w, 0, s );
100100
return w;

tools/quake3/q3map2/brush.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,7 @@ brush_t *AllocBrush( int numSides ){
9393
brush_t *bb;
9494
size_t c;
9595

96-
97-
/* allocate and clear */
98-
if ( numSides <= 0 ) {
99-
Error( "AllocBrush called with numsides = %d", numSides );
100-
}
101-
c = (size_t)&( ( (brush_t*) 0 )->sides[ numSides ] );
96+
c = sizeof(*bb) + (numSides > 6 ? sizeof(side_t)*(numSides - 6) : 0);
10297
bb = safe_malloc( c );
10398
memset( bb, 0, c );
10499
if ( numthreads == 1 ) {

0 commit comments

Comments
 (0)