Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply longjmp(, 0) fix to emscripten longjmp as well #21577

Merged
merged 1 commit into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading