Skip to content

Commit 2316d8a

Browse files
authored
Apply longjmp(, 0) fix to emscripten longjmp as well (#21577)
Fixes: #21486
1 parent faee8d3 commit 2316d8a

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

system/lib/compiler-rt/emscripten_setjmp.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@ uint32_t testSetjmp(uintptr_t id, TableEntry* table, uint32_t size) {
6767
#include "emscripten_internal.h"
6868

6969
void emscripten_longjmp(uintptr_t env, int val) {
70+
// C standard:
71+
// The longjmp function cannot cause the setjmp macro to return
72+
// the value 0; if val is 0, the setjmp macro returns the value 1.
73+
if (val == 0) {
74+
val = 1;
75+
}
7076
setThrew(env, val);
7177
_emscripten_throw_longjmp();
7278
}

test/core/test_longjmp_zero.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* found in the LICENSE file.
66
*/
77

8+
#include <assert.h>
89
#include <stdio.h>
910
#include <setjmp.h>
1011

@@ -13,6 +14,7 @@ int main() {
1314
jmp_buf b1;
1415
int val = setjmp(b1);
1516
if (val) {
17+
assert(val == 1);
1618
printf("success\n");
1719
return 0;
1820
}

0 commit comments

Comments
 (0)