diff --git a/xpcom/tests/static-checker/e1.cpp b/xpcom/tests/static-checker/e1.cpp new file mode 100644 index 00000000000..0a3210fdb61 --- /dev/null +++ b/xpcom/tests/static-checker/e1.cpp @@ -0,0 +1,9 @@ +typedef int PRUint32; +typedef int PRInt32; + +typedef PRUint32 nsresult; + +nsresult foo(__attribute__((user("outparam"))) int *a) { + int k = 0; + return k; +} diff --git a/xpcom/tests/static-checker/e10.cpp b/xpcom/tests/static-checker/e10.cpp new file mode 100644 index 00000000000..fc3a930f534 --- /dev/null +++ b/xpcom/tests/static-checker/e10.cpp @@ -0,0 +1,13 @@ +typedef int PRUint32; +typedef int PRInt32; + +typedef PRUint32 nsresult; +typedef short PRUnichar; + +nsresult bar(nsACString &a); +nsresult baz(); + +nsresult foo(nsACString &a) { + bar(a); + return baz(); +} diff --git a/xpcom/tests/static-checker/e11.cpp b/xpcom/tests/static-checker/e11.cpp new file mode 100644 index 00000000000..d619c6417c4 --- /dev/null +++ b/xpcom/tests/static-checker/e11.cpp @@ -0,0 +1,11 @@ +typedef int PRUint32; +typedef int PRInt32; + +typedef PRUint32 nsresult; +typedef short PRUnichar; + +nsresult bar(PRUnichar **a, int q); + +nsresult foo(PRUnichar **a) { + return bar(a, 0); +} diff --git a/xpcom/tests/static-checker/e2.cpp b/xpcom/tests/static-checker/e2.cpp new file mode 100644 index 00000000000..d23529f8674 --- /dev/null +++ b/xpcom/tests/static-checker/e2.cpp @@ -0,0 +1,9 @@ +typedef int PRUint32; +typedef int PRInt32; + +typedef PRUint32 nsresult; + +nsresult foo(__attribute__((user("outparam"))) int *a) { + *a = 9; + return 1; +} diff --git a/xpcom/tests/static-checker/e3.cpp b/xpcom/tests/static-checker/e3.cpp new file mode 100644 index 00000000000..22a32c978b6 --- /dev/null +++ b/xpcom/tests/static-checker/e3.cpp @@ -0,0 +1,9 @@ +typedef int PRUint32; +typedef int PRInt32; + +typedef PRUint32 nsresult; + +nsresult foo(__attribute__((user("outparam"))) int *a) { + *a = 0; + return 1; +} diff --git a/xpcom/tests/static-checker/e4.cpp b/xpcom/tests/static-checker/e4.cpp new file mode 100644 index 00000000000..2874ebdbd6c --- /dev/null +++ b/xpcom/tests/static-checker/e4.cpp @@ -0,0 +1,11 @@ +typedef int PRUint32; +typedef int PRInt32; + +typedef PRUint32 nsresult; + +nsresult bar(int *a); + +nsresult foo(__attribute__((user("outparam"))) int *a) { + bar(a); + return 0; +} diff --git a/xpcom/tests/static-checker/e5.cpp b/xpcom/tests/static-checker/e5.cpp new file mode 100644 index 00000000000..0db6d92c39d --- /dev/null +++ b/xpcom/tests/static-checker/e5.cpp @@ -0,0 +1,9 @@ +typedef int PRUint32; +typedef int PRInt32; + +typedef PRUint32 nsresult; + +nsresult foo(__attribute__((user("inoutparam"))) int *a) { + *a = 9; + return 1; +} diff --git a/xpcom/tests/static-checker/e6.cpp b/xpcom/tests/static-checker/e6.cpp new file mode 100644 index 00000000000..86b7a9e650b --- /dev/null +++ b/xpcom/tests/static-checker/e6.cpp @@ -0,0 +1,14 @@ +typedef int PRUint32; +typedef int PRInt32; + +typedef PRUint32 nsresult; + +class A { +}; + +nsresult bar(__attribute__((user("outparam"))) void **a); + +nsresult foo(__attribute__((user("outparam"))) A **a) { + nsresult rv = bar((void **) a); + return 1; +} diff --git a/xpcom/tests/static-checker/e7.cpp b/xpcom/tests/static-checker/e7.cpp new file mode 100644 index 00000000000..8d2d823053f --- /dev/null +++ b/xpcom/tests/static-checker/e7.cpp @@ -0,0 +1,11 @@ +typedef int PRUint32; +typedef int PRInt32; + +typedef PRUint32 nsresult; + +nsresult bar(char **a, int q); + +nsresult foo(char **a) { + bar(a, 0); + return 0; +} diff --git a/xpcom/tests/static-checker/e8.cpp b/xpcom/tests/static-checker/e8.cpp new file mode 100644 index 00000000000..35d1bbb3b12 --- /dev/null +++ b/xpcom/tests/static-checker/e8.cpp @@ -0,0 +1,8 @@ +typedef int PRUint32; +typedef int PRInt32; + +typedef PRUint32 nsresult; + +nsresult foo(char **a) { + return 0; +} diff --git a/xpcom/tests/static-checker/e9.cpp b/xpcom/tests/static-checker/e9.cpp new file mode 100644 index 00000000000..cd5aa1a0944 --- /dev/null +++ b/xpcom/tests/static-checker/e9.cpp @@ -0,0 +1,9 @@ +typedef int PRUint32; +typedef int PRInt32; + +typedef PRUint32 nsresult; +typedef short PRUnichar; + +nsresult foo(PRUnichar **a) { + return 0; +} diff --git a/xpcom/tests/static-checker/o1.cpp b/xpcom/tests/static-checker/o1.cpp new file mode 100644 index 00000000000..40a24915313 --- /dev/null +++ b/xpcom/tests/static-checker/o1.cpp @@ -0,0 +1,9 @@ +typedef int PRUint32; +typedef int PRInt32; + +typedef PRUint32 nsresult; + +nsresult foo(__attribute__((user("outparam"))) int *a) { + *a = 1; + return 0; +} diff --git a/xpcom/tests/static-checker/o10.cpp b/xpcom/tests/static-checker/o10.cpp new file mode 100644 index 00000000000..362a0558097 --- /dev/null +++ b/xpcom/tests/static-checker/o10.cpp @@ -0,0 +1,22 @@ +typedef int PRUint32; +typedef int PRInt32; + +typedef PRUint32 nsresult; +typedef short PRUnichar; + +class nsAString { +public: + void Read() const; + void Mutate(); +}; + +nsresult bar(); + +nsresult foo(nsAString &s) { + nsresult rv = bar(); + s.Read(); + if (rv == 0) { + s.Mutate(); + } + return rv; +} diff --git a/xpcom/tests/static-checker/o2.cpp b/xpcom/tests/static-checker/o2.cpp new file mode 100644 index 00000000000..e5203fd1ada --- /dev/null +++ b/xpcom/tests/static-checker/o2.cpp @@ -0,0 +1,15 @@ +typedef int PRUint32; +typedef int PRInt32; + +typedef PRUint32 nsresult; + +int x; + +nsresult foo(__attribute__((user("outparam"))) int *a) { + if (x) { + *a = 1; + return 0; + } else { + return 1; + } +} diff --git a/xpcom/tests/static-checker/o3.cpp b/xpcom/tests/static-checker/o3.cpp new file mode 100644 index 00000000000..0e78c8835b6 --- /dev/null +++ b/xpcom/tests/static-checker/o3.cpp @@ -0,0 +1,13 @@ +typedef int PRUint32; +typedef int PRInt32; + +typedef PRUint32 nsresult; + +nsresult foo(__attribute__((user("outparam"))) int *a) { + int x; + + if (x == 0) { + *a = 1; + } + return x; +} diff --git a/xpcom/tests/static-checker/o4.cpp b/xpcom/tests/static-checker/o4.cpp new file mode 100644 index 00000000000..c4678602395 --- /dev/null +++ b/xpcom/tests/static-checker/o4.cpp @@ -0,0 +1,21 @@ +typedef int PRUint32; +typedef int PRInt32; + +typedef PRUint32 nsresult; + +nsresult bar(__attribute__((user("outparam"))) int q); + +inline int NS_FAILED(nsresult _nsresult) { + return _nsresult & 0x80000000; +} + +inline int NS_SUCCEEDED(nsresult _nsresult) { + return !(_nsresult & 0x80000000); +} + +nsresult foo(__attribute__((user("outparam"))) int *a) { + nsresult rv = bar(4); + if (NS_FAILED(rv)) return rv; + *a = 1; + return 0; +} diff --git a/xpcom/tests/static-checker/o5.cpp b/xpcom/tests/static-checker/o5.cpp new file mode 100644 index 00000000000..4d05b50314b --- /dev/null +++ b/xpcom/tests/static-checker/o5.cpp @@ -0,0 +1,11 @@ +typedef int PRUint32; +typedef int PRInt32; + +typedef PRUint32 nsresult; + +nsresult bar(__attribute__((user("outparam"))) int *a); + +nsresult foo(__attribute__((user("outparam"))) int *a) { + int rv = bar(a); + return rv; +} diff --git a/xpcom/tests/static-checker/o6.cpp b/xpcom/tests/static-checker/o6.cpp new file mode 100644 index 00000000000..1b08b14128a --- /dev/null +++ b/xpcom/tests/static-checker/o6.cpp @@ -0,0 +1,11 @@ +typedef int PRUint32; +typedef int PRInt32; + +typedef PRUint32 nsresult; + +nsresult foo(__attribute__((user("outparam"))) int *a) { + if (a) { + *a = 1; + } + return 0; +} diff --git a/xpcom/tests/static-checker/o7.cpp b/xpcom/tests/static-checker/o7.cpp new file mode 100644 index 00000000000..b316df51eae --- /dev/null +++ b/xpcom/tests/static-checker/o7.cpp @@ -0,0 +1,8 @@ +typedef int PRUint32; +typedef int PRInt32; + +typedef PRUint32 nsresult; + +nsresult foo(__attribute__((user("inoutparam"))) int *a) { + return 0; +} diff --git a/xpcom/tests/static-checker/o8.cpp b/xpcom/tests/static-checker/o8.cpp new file mode 100644 index 00000000000..7a4d213dcfa --- /dev/null +++ b/xpcom/tests/static-checker/o8.cpp @@ -0,0 +1,8 @@ +typedef int PRUint32; +typedef int PRInt32; + +typedef PRUint32 nsresult; + +nsresult foo(char *a) { + return 0; +} diff --git a/xpcom/tests/static-checker/o9.cpp b/xpcom/tests/static-checker/o9.cpp new file mode 100644 index 00000000000..efe9284adbf --- /dev/null +++ b/xpcom/tests/static-checker/o9.cpp @@ -0,0 +1,9 @@ +typedef int PRUint32; +typedef int PRInt32; + +typedef PRUint32 nsresult; +typedef short PRUnichar; + +nsresult foo(PRUnichar *a) { + return 0; +}