Skip to content

Commit d50b8c9

Browse files
committed
[PSEH] Fix a bug with try inside except
PSEH has 2 scopes: an outer scope, that starts with _SEH3_TRY and ends with _SEH3_END, and an inner scope that goes around the try block only. PSEH tracks try-levels by using an enum, which increments at every new TRY scrope, and which needs to be accessible in the outer scope for all registration and cleanup to work. But it should only increment when nested within the inner try scope, not from the except scope. This is fixed by adding an additional _SEH3$_InnerTryLevel, which increments only within the try block, but resets to the parent-value outside of it. Should fix CORE-20316.
1 parent 194be7a commit d50b8c9

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

sdk/lib/pseh/include/pseh/pseh3.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ void _SEH3$_UnregisterTryLevel(
112112
enum
113113
{
114114
_SEH3$_TryLevel = -1,
115+
_SEH3$_InnerTryLevel = -1,
115116
};
116117

117118
#ifndef __clang__
@@ -375,7 +376,7 @@ _Pragma("GCC diagnostic pop") \
375376
\
376377
/* Count the try level. Outside of any __try, _SEH3$_TryLevel is -1 */ \
377378
enum { \
378-
_SEH3$_PreviousTryLevel = _SEH3$_TryLevel, \
379+
_SEH3$_PreviousTryLevel = _SEH3$_InnerTryLevel, \
379380
_SEH3$_TryLevel = _SEH3$_PreviousTryLevel + 1, \
380381
}; \
381382
\
@@ -388,6 +389,11 @@ _Pragma("GCC diagnostic pop") \
388389
goto _SEH3$_l_BeforeTry; \
389390
{ \
390391
__label__ _SEH3$_l_Leave; \
392+
\
393+
enum { \
394+
_SEH3$_InnerTryLevel = _SEH3$_TryLevel, \
395+
}; \
396+
\
391397
_SEH3$_l_Leave: (void)0; \
392398
/* Silence warning */ goto _SEH3$_l_AfterTry; \
393399
/* Silence warning */ goto _SEH3$_l_Leave; \

0 commit comments

Comments
 (0)