aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/library.js2
-rw-r--r--tests/emscripten_log/emscripten_log.cpp8
2 files changed, 9 insertions, 1 deletions
diff --git a/src/library.js b/src/library.js
index cd451c57..62695ae7 100644
--- a/src/library.js
+++ b/src/library.js
@@ -9025,7 +9025,7 @@ LibraryManager.library = {
}
// Truncate output to avoid writing past bounds.
if (callstack.length > maxbytes-1) {
- callstack.slice(0, maxbytes-1);
+ callstack = callstack.slice(0, maxbytes-1);
}
// Output callstack string as C string to HEAP.
writeStringToMemory(callstack, str, false);
diff --git a/tests/emscripten_log/emscripten_log.cpp b/tests/emscripten_log/emscripten_log.cpp
index d7cfe484..5973e94c 100644
--- a/tests/emscripten_log/emscripten_log.cpp
+++ b/tests/emscripten_log/emscripten_log.cpp
@@ -99,6 +99,14 @@ void __attribute__((noinline)) bar(int = 0, char * = 0, double = 0) // Arbitrary
char str[1024];
emscripten_get_callstack(EM_LOG_NO_PATHS | EM_LOG_JS_STACK, str, 1024);
+ // Test that obtaining a truncated callstack works. (https://github.com/kripken/emscripten/issues/2171)
+ char *buffer = new char[21];
+ buffer[20] = 0x01; // Magic sentinel that should not change its value.
+ emscripten_get_callstack(EM_LOG_C_STACK | EM_LOG_DEMANGLE | EM_LOG_NO_PATHS | EM_LOG_FUNC_PARAMS, buffer, 20);
+ MYASSERT(!!strstr(buffer, "at bar(int,"), "Truncated callstack was %s!", buffer);
+ MYASSERT(buffer[20] == 0x01);
+ delete[] buffer;
+
/* With EM_LOG_JS_STACK, the callstack will be
at __Z3bariPcd (src.cpp.o.js:5394:12)
at __Z3FooIiEvv (src.cpp.o.js:5417:4)