summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Mann <mmann78@netscape.net>2016-07-14 20:04:48 -0400
committerMichael Mann <mmann78@netscape.net>2016-07-15 01:48:49 +0000
commit2c3127940ad65ce503dba1308549719e57f87458 (patch)
tree5ede2b50f8ed7a3b55b0cbb85e5e7d97ab52f733
parent8428d3a927e46d3be13a8d52d04b7697b0b99b80 (diff)
downloadwireshark-2c3127940ad65ce503dba1308549719e57f87458.tar.gz
exntest.c: Create local functions to handle "nesting" TRY/CATCH macros to fix shadow warnings.
Found by VS Code Analysis, although it appears it's been discovered before and warranted the DIAG_ON/OFF macros. Those have been removed as this is believed to be a good solution. Change-Id: I376d816855366d55affe7b9e4b8616509aa4e7fe Reviewed-on: https://code.wireshark.org/review/16447 Reviewed-by: Michael Mann <mmann78@netscape.net>
-rw-r--r--epan/exntest.c88
1 files changed, 52 insertions, 36 deletions
diff --git a/epan/exntest.c b/epan/exntest.c
index 92eac68f5a..5c4ecdcfd8 100644
--- a/epan/exntest.c
+++ b/epan/exntest.c
@@ -26,7 +26,55 @@
gboolean failed = FALSE;
-DIAG_OFF(shadow)
+static void
+finally_called_uncaught_exception(volatile unsigned int* called)
+{
+ TRY {
+ THROW(BoundsError);
+ }
+ FINALLY {
+ (*called)++;
+ }
+ ENDTRY;
+}
+
+static void
+finally_called_rethrown_exception(volatile unsigned int* thrown, volatile unsigned int* called)
+{
+ TRY {
+ THROW(BoundsError);
+ }
+ CATCH_ALL {
+ (*thrown) += 10;
+ RETHROW;
+ }
+ FINALLY {
+ (*called) += 10;
+ }
+ ENDTRY;
+}
+
+static void
+finally_called_exception_from_catch(volatile unsigned int* thrown, volatile unsigned int* called)
+{
+ TRY {
+ THROW(BoundsError);
+ }
+ CATCH_ALL {
+ if((*thrown) > 0) {
+ printf("05: Looping exception\n");
+ failed = TRUE;
+ } else {
+ (*thrown) += 10;
+ THROW(BoundsError);
+ }
+ }
+ FINALLY {
+ (*called) += 10;
+ }
+ ENDTRY;
+}
+
void
run_tests(void)
{
@@ -101,13 +149,7 @@ run_tests(void)
/* check that finally is called on an uncaught exception */
ex_thrown = finally_called = 0;
TRY {
- TRY {
- THROW(BoundsError);
- }
- FINALLY {
- finally_called ++;
- }
- ENDTRY;
+ finally_called_uncaught_exception(&finally_called);
}
CATCH(BoundsError) {
ex_thrown++;
@@ -128,17 +170,7 @@ run_tests(void)
/* check that finally is called on an rethrown exception */
ex_thrown = finally_called = 0;
TRY {
- TRY {
- THROW(BoundsError);
- }
- CATCH_ALL {
- ex_thrown += 10;
- RETHROW;
- }
- FINALLY {
- finally_called += 10;
- }
- ENDTRY;
+ finally_called_rethrown_exception(&ex_thrown, &finally_called);
}
CATCH(BoundsError) {
ex_thrown ++;
@@ -162,22 +194,7 @@ run_tests(void)
/* check that finally is called on an exception thrown from a CATCH block */
ex_thrown = finally_called = 0;
TRY {
- TRY {
- THROW(BoundsError);
- }
- CATCH_ALL {
- if(ex_thrown > 0) {
- printf("05: Looping exception\n");
- failed = TRUE;
- } else {
- ex_thrown += 10;
- THROW(BoundsError);
- }
- }
- FINALLY {
- finally_called += 10;
- }
- ENDTRY;
+ finally_called_exception_from_catch(&ex_thrown, &finally_called);
}
CATCH(BoundsError) {
ex_thrown ++;
@@ -200,7 +217,6 @@ run_tests(void)
if(failed == FALSE )
printf("success\n");
}
-DIAG_ON(shadow)
int main(void)
{