Fix dotnet/coreclr#27326 - Don't decrement curOffsReg when it is 0, as it is an unsig...
authorBrian Sullivan <briansul@microsoft.com>
Thu, 31 Oct 2019 20:37:56 +0000 (13:37 -0700)
committerGitHub <noreply@github.com>
Thu, 31 Oct 2019 20:37:56 +0000 (13:37 -0700)
Fixes dotnet/coreclr#27326

Commit migrated from https://github.com/dotnet/coreclr/commit/21c0fefd52cf8035d4ce6e3d410223cc1e2533ea

src/coreclr/src/vm/eetwain.cpp

index a1a8065..87dbdba 100644 (file)
@@ -4456,13 +4456,24 @@ bool EECodeManager::EnumGcRefs( PREGDISPLAY     pContext,
 
     if  (info.interruptible)
     {
-        // If we are not on the active stack frame, we need to report gc registers
-        // that are live before the call. The reason is that the liveness of gc registers
-        // may change across a call to a method that does not return. In this case the instruction
-        // after the call may be a jump target and a register that didn't have a live gc pointer
-        // before the call may have a live gc pointer after the jump. To make sure we report the
-        // registers that have live gc pointers before the call we subtract 1 from curOffs.
-        unsigned curOffsRegs = (flags & ActiveStackFrame) != 0 ? curOffs : curOffs - 1;
+        unsigned curOffsRegs = curOffs;
+
+        // Don't decrement curOffsRegs when it is 0, as it is an unsigned and will wrap to MAX_UINT
+        //
+        if (curOffsRegs > 0)
+        {
+            // If we are not on the active stack frame, we need to report gc registers
+            // that are live before the call. The reason is that the liveness of gc registers
+            // may change across a call to a method that does not return. In this case the instruction
+            // after the call may be a jump target and a register that didn't have a live gc pointer
+            // before the call may have a live gc pointer after the jump. To make sure we report the
+            // registers that have live gc pointers before the call we subtract 1 from curOffs.
+            if ((flags & ActiveStackFrame) == 0)
+            {
+                // We are not the top most stack frame (i.e. the ActiveStackFrame)
+                curOffsRegs--;   // decrement curOffsRegs
+            }
+        }
 
         pushedSize = scanArgRegTableI(skipToArgReg(info, table), curOffsRegs, curOffs, &info);