From 82472d0da405cd839b8c7399303b07e13923b8ed Mon Sep 17 00:00:00 2001 From: Aditya Mandaleeka Date: Tue, 16 Feb 2016 19:29:14 -0800 Subject: [PATCH] Fix DBG_ShouldCheckStackAlignment. --- src/pal/src/misc/dbgmsg.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/pal/src/misc/dbgmsg.cpp b/src/pal/src/misc/dbgmsg.cpp index 7a496b6a3f2c..3bd800307fa4 100644 --- a/src/pal/src/misc/dbgmsg.cpp +++ b/src/pal/src/misc/dbgmsg.cpp @@ -818,7 +818,18 @@ bool DBG_ShouldCheckStackAlignment() if (caMode == CheckAlignment_Uninitialized) { - char* checkAlignmentSettings = EnvironGetenv(PAL_CHECK_ALIGNMENT_MODE); + char* checkAlignmentSettings; + if (palEnvironment == nullptr) + { + // This function might be called before the PAL environment is initialized. + // In this case, use the system getenv instead. + checkAlignmentSettings = ::getenv(PAL_CHECK_ALIGNMENT_MODE); + } + else + { + checkAlignmentSettings = EnvironGetenv(PAL_CHECK_ALIGNMENT_MODE); + } + caMode = checkAlignmentSettings ? (CheckAlignmentMode)atoi(checkAlignmentSettings) : CheckAlignment_Default;