Skip to content

Commit 12c5f32

Browse files
committed
Correct handling of return value of N_OP_unwind()
The return value of N_OP_unwind is really of type LispPTR *, however it was declared as UNSIGNED (effectively uintptr_t) so that the ERROR_EXIT macro could be used to return an error indication (-1, =UINT_MAX). The call site checked for the error condition with (int)result < 0, not accounting for the case where a native pointer may have the high-order bit set. We correct this problem by declaring the return type as LispPTR *, and expand the ERROR_EXIT macro in place substituting (LispPTR *)(-1) as the error return value, and at the single call site check for equality with that same value. The test case was executing the opcode tester on a Raspberry Pi or a BeagleBone Black/Debian 10.3 where the non-error result was > 0xB0000000 modified: inc/inlineC.h modified: inc/unwinddefs.h modified: src/unwind.c
1 parent d717946 commit 12c5f32

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

inc/inlineC.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -852,8 +852,7 @@ nextop2; \
852852

853853
#define UNWIND(n, m) \
854854
{ \
855-
if ((INT)(CSTKPTRL = (LispPTR *) \
856-
N_OP_unwind(CSTKPTR, TOPOFSTACK, n, m)) < 0) \
855+
if ((CSTKPTRL = N_OP_unwind(CSTKPTR, TOPOFSTACK, n, m)) == (LispPTR *)-1) \
857856
goto unwind_err; \
858857
POP; \
859858
nextop3; \

inc/unwinddefs.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#ifndef UNWINDDEFS_H
22
#define UNWINDDEFS_H 1
3-
UNSIGNED N_OP_unwind(register LispPTR *cstkptr, register LispPTR tos, int n, int keep);
3+
LispPTR *N_OP_unwind(register LispPTR *cstkptr, register LispPTR tos, int n, int keep);
44
#endif

src/unwind.c

+6-3
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
#include "unwinddefs.h"
3030

31-
UNSIGNED N_OP_unwind(register LispPTR *cstkptr, register LispPTR tos, int n, int keep) {
31+
LispPTR *N_OP_unwind(register LispPTR *cstkptr, register LispPTR tos, int n, int keep) {
3232
register int num; /* number of UNBOUND slot */
3333
register LispPTR *endptr; /* unwind limit */
3434
register LispPTR *lastpvar; /* points PVar slot that is unbounded. */
@@ -64,7 +64,10 @@ UNSIGNED N_OP_unwind(register LispPTR *cstkptr, register LispPTR tos, int n, int
6464

6565
if (endptr > cstkptr) {
6666
CurrentStackPTR = (DLword *)cstkptr;
67-
ERROR_EXIT(tos);
67+
/* this would be ERROR_EXIT(tos); but for having to return a pointer */
68+
TopOfStack = tos;
69+
Error_Exit = 1;
70+
return (LispPTR *)(-1);
6871
}
6972
*cstkptr++ = tos;
7073

@@ -85,7 +88,7 @@ UNSIGNED N_OP_unwind(register LispPTR *cstkptr, register LispPTR tos, int n, int
8588
/* endptr = cstkptr */
8689

8790
if (keep) { *(cstkptr++) = tos; }
88-
return ((UNSIGNED)cstkptr);
91+
return (cstkptr);
8992

9093
} /* N_OP_unwind */
9194

0 commit comments

Comments
 (0)