From c63a0364317eef4f1f4e7a325b3ba1f7dc26eec5 Mon Sep 17 00:00:00 2001 From: Benjamin Smedberg Date: Mon, 27 Jul 2009 10:47:22 -0400 Subject: [PATCH] Resolve the static-analysis bustage from bug 498938 by recognizing COND_EXPR. --- xpcom/analysis/stack.js | 1 + xpcom/tests/static-checker/Makefile.in | 2 ++ xpcom/tests/static-checker/StackCond.cpp | 12 ++++++++++++ xpcom/tests/static-checker/StackCondBad.cpp | 12 ++++++++++++ xpcom/tests/static-checker/o3.cpp | 4 +--- 5 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 xpcom/tests/static-checker/StackCond.cpp create mode 100644 xpcom/tests/static-checker/StackCondBad.cpp diff --git a/xpcom/analysis/stack.js b/xpcom/analysis/stack.js index 90df3fe0e45..884778276f6 100644 --- a/xpcom/analysis/stack.js +++ b/xpcom/analysis/stack.js @@ -161,6 +161,7 @@ function process_cp_pre_genericize(fndecl) let assign = stack[i]; switch (TREE_CODE(assign)) { case VAR_DECL: + case COND_EXPR: break; case INIT_EXPR: diff --git a/xpcom/tests/static-checker/Makefile.in b/xpcom/tests/static-checker/Makefile.in index 66c81a61e94..5647b02b52d 100644 --- a/xpcom/tests/static-checker/Makefile.in +++ b/xpcom/tests/static-checker/Makefile.in @@ -58,10 +58,12 @@ STACK_FAILURE_TESTCASES = \ StackVector.cpp \ StackConditional.cpp \ StackAggrInit.cpp \ + StackCondBad.cpp \ $(NULL) STACK_PASS_TESTCASES = \ StackPlacementNewOK.cpp \ + StackCond.cpp \ $(NULL) OUTPARAMS_WARNING_TESTCASES = \ diff --git a/xpcom/tests/static-checker/StackCond.cpp b/xpcom/tests/static-checker/StackCond.cpp new file mode 100644 index 00000000000..ff93bfec95e --- /dev/null +++ b/xpcom/tests/static-checker/StackCond.cpp @@ -0,0 +1,12 @@ +#include "nscore.h" + +struct A +{ +}; + +A* tfunc(int len) +{ + A arr[5]; + A* a = len <= 5 ? arr : new A[len]; + return a; +} diff --git a/xpcom/tests/static-checker/StackCondBad.cpp b/xpcom/tests/static-checker/StackCondBad.cpp new file mode 100644 index 00000000000..2d8b6818707 --- /dev/null +++ b/xpcom/tests/static-checker/StackCondBad.cpp @@ -0,0 +1,12 @@ +#include "nscore.h" + +struct NS_STACK_CLASS A +{ +}; + +A* tfunc(int len) +{ + A arr[5]; + A* a = len <= 5 ? arr : new A[len]; + return a; +} diff --git a/xpcom/tests/static-checker/o3.cpp b/xpcom/tests/static-checker/o3.cpp index 0e78c8835b6..13449e9717e 100644 --- a/xpcom/tests/static-checker/o3.cpp +++ b/xpcom/tests/static-checker/o3.cpp @@ -3,9 +3,7 @@ typedef int PRInt32; typedef PRUint32 nsresult; -nsresult foo(__attribute__((user("outparam"))) int *a) { - int x; - +nsresult foo(nsresult x, __attribute__((user("outparam"))) int *a) { if (x == 0) { *a = 1; }