Skip to content

Commit a5525d2

Browse files
author
Pavel Kovalenko
committed
Fix potential stack overflow in CRender::LoadBuffers.
1 parent ed73dea commit a5525d2

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/Layers/xrRenderPC_R4/r4_loader.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,14 +194,14 @@ void CRender::LoadBuffers (CStreamReader *base_fs, BOOL _alternative)
194194
u32 count = fs->r_u32();
195195
_DC.resize (count);
196196
_VB.resize (count);
197+
u32 bufferSize = (MAXD3DDECLLENGTH+1)*sizeof(D3DVERTEXELEMENT9);
198+
D3DVERTEXELEMENT9* dcl = (D3DVERTEXELEMENT9*)_alloca(bufferSize);
197199
for (u32 i=0; i<count; i++)
198200
{
199201
// decl
200202
// D3DVERTEXELEMENT9* dcl = (D3DVERTEXELEMENT9*) fs().pointer();
201-
u32 buffer_size = (MAXD3DDECLLENGTH+1)*sizeof(D3DVERTEXELEMENT9);
202-
D3DVERTEXELEMENT9 *dcl = (D3DVERTEXELEMENT9*)_alloca(buffer_size);
203-
fs->r (dcl,buffer_size);
204-
fs->advance (-(int)buffer_size);
203+
fs->r (dcl,bufferSize);
204+
fs->advance (-(int)bufferSize);
205205

206206
u32 dcl_len = D3DXGetDeclLength (dcl)+1;
207207
_DC[i].resize (dcl_len);

0 commit comments

Comments
 (0)