Fix JIT wrong type cast; hardening only (#1060)

We believe that the cast to a `short` value (16-bit) cannot currently overflow, and truncation behaviour is not reachable in the latest release of PCRE2.

As hardening behaviour, the cast is fixed.

Found by Aram Zahedi.
diff --git a/src/pcre2_jit_compile.c b/src/pcre2_jit_compile.c
index d999cbd..4ae4b81 100644
--- a/src/pcre2_jit_compile.c
+++ b/src/pcre2_jit_compile.c
@@ -2425,8 +2425,10 @@
   if (SLJIT_UNLIKELY(possessive == length))
     return stack_restore ? no_frame : no_stack;
 
+  SLJIT_ASSERT(length >= 0 && length < 0x1000000);
   if (length > 0)
     return length + 1;
+
   return stack_restore ? no_frame : no_stack;
 }
 
@@ -11156,11 +11158,10 @@
     int data;
     int framesize = BACKTRACK_AS(bracket_backtrack)->u.framesize;
 
-    SLJIT_ASSERT(SHRT_MIN <= framesize && framesize < SHRT_MAX / 2);
     /* We temporarily encode the needs_control_head in the lowest bit.
        The real value should be short enough for this operation to work
        without triggering Undefined Behaviour. */
-    data = (int)((short)((unsigned short)framesize << 1) | (needs_control_head ? 1 : 0));
+    data = (int)(((unsigned int)framesize << 1) | (needs_control_head ? 1 : 0));
     BACKTRACK_AS(bracket_backtrack)->u.framesize = data;
   }
 
diff --git a/testdata/testinput2 b/testdata/testinput2
index 6eaeb75..b6d7af9 100644
--- a/testdata/testinput2
+++ b/testdata/testinput2
@@ -8645,4 +8645,14 @@
 /A\KBC/auto_callout
     _ABC_
 
+# JIT: the frame of an atomic group containing more than 16383 frame words
+# (here 5462 copies of a capture group) must not overflow when stored.
+# The preceding callout leaves a zero in the stale stack slot.
+
+/x(?C1)/
+    x
+
+/(?>a(){5462}b)|a/
+    a\=jitstack=1024
+
 # End of testinput2
diff --git a/testdata/testoutput2 b/testdata/testoutput2
index 54bbedf..2f9ae42 100644
--- a/testdata/testoutput2
+++ b/testdata/testoutput2
@@ -24273,6 +24273,20 @@
  +5   ^ ^     End of pattern
  0: BC
 
+# JIT: the frame of an atomic group containing more than 16383 frame words
+# (here 5462 copies of a capture group) must not overflow when stored.
+# The preceding callout leaves a zero in the stale stack slot.
+
+/x(?C1)/
+    x
+--->x
+  1 ^^    End of pattern
+ 0: x
+
+/(?>a(){5462}b)|a/
+    a\=jitstack=1024
+ 0: a
+
 # End of testinput2
 Error -80: PCRE2_ERROR_BADDATA (unknown error number)
 Error -62: bad serialized data