Skip to content

Commit

Permalink
Apply longjmp(, 0) fix to emscripten longjmp as well
Browse files Browse the repository at this point in the history
  • Loading branch information
yamt committed Mar 21, 2024
1 parent faee8d3 commit 761c454
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
6 changes: 6 additions & 0 deletions system/lib/compiler-rt/emscripten_setjmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ uint32_t testSetjmp(uintptr_t id, TableEntry* table, uint32_t size) {
#include "emscripten_internal.h"

void emscripten_longjmp(uintptr_t env, int val) {
// C standard:
// The longjmp function cannot cause the setjmp macro to return
// the value 0; if val is 0, the setjmp macro returns the value 1.
if (val == 0) {
val = 1;
}
setThrew(env, val);
_emscripten_throw_longjmp();
}
Expand Down
2 changes: 2 additions & 0 deletions test/core/test_longjmp_zero.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* found in the LICENSE file.
*/

#include <assert.h>
#include <stdio.h>
#include <setjmp.h>

Expand All @@ -13,6 +14,7 @@ int main() {
jmp_buf b1;
int val = setjmp(b1);
if (val) {
assert(val == 1);
printf("success\n");
return 0;
}
Expand Down

0 comments on commit 761c454

Please sign in to comment.