Skip to content

Commit 43536dc

Browse files
author
Pavel Kovalenko
committed
Fix potential stack overflow in CRender::LoadBuffers (R3).
1 parent a5525d2 commit 43536dc

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/Layers/xrRenderPC_R3/r3_loader.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,14 +219,14 @@ void CRender::LoadBuffers (CStreamReader *base_fs, BOOL _alternative)
219219
u32 count = fs->r_u32();
220220
_DC.resize (count);
221221
_VB.resize (count);
222+
u32 bufferSize = (MAXD3DDECLLENGTH+1)*sizeof(D3DVERTEXELEMENT9);
223+
D3DVERTEXELEMENT9* dcl = (D3DVERTEXELEMENT9*)_alloca(bufferSize);
222224
for (u32 i=0; i<count; i++)
223225
{
224226
// decl
225227
// D3DVERTEXELEMENT9* dcl = (D3DVERTEXELEMENT9*) fs().pointer();
226-
u32 buffer_size = (MAXD3DDECLLENGTH+1)*sizeof(D3DVERTEXELEMENT9);
227-
D3DVERTEXELEMENT9 *dcl = (D3DVERTEXELEMENT9*)_alloca(buffer_size);
228-
fs->r (dcl,buffer_size);
229-
fs->advance (-(int)buffer_size);
228+
fs->r (dcl,bufferSize);
229+
fs->advance (-(int)bufferSize);
230230

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

0 commit comments

Comments
 (0)