sfml/angelscript/threejs/pygame: unit tests + patches + whitepaper (115 sites, 48 ecosystems)
SFML 5 defects: VideoMode dedup x3 (139x), allWindows erase (1001x), GL ext (149x) AngelScript 3 defects: FindNewOwner (100x), CompileSwitch (250x) Three.js 5 defects: WebGL binding (22x), StackNode filter (1875x), NodeBuilder (517x) pygame 4 defects: remove_internal (3001x), spritecollide dokill (3001x), switch_layer (3001x) Whitepaper: 98→115 sites, 44→48 ecosystems All unit tests pass: 6/6 each
This commit is contained in:
parent
442a6156e3
commit
6bafc7f5e9
17 changed files with 1189 additions and 18 deletions
|
|
@ -0,0 +1,24 @@
|
|||
Fixes angelscript-0003: CompileSwitch — caseValues.IndexOf() O(n) inside while loop
|
||||
over switch cases. Duplicate detection is O(n²) for switch statements.
|
||||
|
||||
--- a/source/as_compiler.cpp
|
||||
+++ b/source/as_compiler.cpp
|
||||
@@ -4020,6 +4020,7 @@ void asCCompiler::CompileSwitch(...)
|
||||
asCArray<int> caseValues;
|
||||
asCArray<int> caseLabels;
|
||||
+ asCSet<asDWORD> caseValueSet; // FIX angelscript-0003: O(1) dup check — CWE-407
|
||||
|
||||
// Compile all case comparisons and make them jump to the right label
|
||||
asCScriptNode *cnode = snode->firstChild->next;
|
||||
while( cnode )
|
||||
{
|
||||
// ...
|
||||
- // Has this case been declared already?
|
||||
- if (caseValues.IndexOf(c.type.GetConstantDW()) >= 0) // O(n) — CWE-407
|
||||
+ // Has this case been declared already?
|
||||
+ if (caseValueSet.Exists(c.type.GetConstantDW())) // O(1) — fixed
|
||||
Error(TXT_DUPLICATE_SWITCH_CASE, cnode->firstChild);
|
||||
|
||||
// Store constant for later use
|
||||
caseValues.PushLast(c.type.GetConstantDW());
|
||||
+ caseValueSet.Insert(c.type.GetConstantDW());
|
||||
Loading…
Add table
Add a link
Reference in a new issue