From 2c3127940ad65ce503dba1308549719e57f87458 Mon Sep 17 00:00:00 2001 From: Michael Mann Date: Thu, 14 Jul 2016 20:04:48 -0400 Subject: [PATCH] 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 --- epan/exntest.c | 88 +++++++++++++++++++++++++++++--------------------- 1 file 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) {