Skip to content

Commit 305cc63

Browse files
Andrews54757iThalay
authored andcommitted
stream.wasm : fix invalid memory access when no segments (ggml-org#1902)
No segments may be returned when a smaller sample buffer (EG 2048 samples) is sent to the worker.
1 parent 8d70755 commit 305cc63

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

examples/stream.wasm/emscripten.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,11 @@ void stream_main(size_t index) {
103103

104104
{
105105
const int n_segments = whisper_full_n_segments(ctx);
106-
for (int i = n_segments - 1; i < n_segments; ++i) {
107-
const char * text = whisper_full_get_segment_text(ctx, i);
106+
if (n_segments > 0) {
107+
const char * text = whisper_full_get_segment_text(ctx, n_segments - 1);
108108

109-
const int64_t t0 = whisper_full_get_segment_t0(ctx, i);
110-
const int64_t t1 = whisper_full_get_segment_t1(ctx, i);
109+
const int64_t t0 = whisper_full_get_segment_t0(ctx, n_segments - 1);
110+
const int64_t t1 = whisper_full_get_segment_t1(ctx, n_segments - 1);
111111

112112
printf("transcribed: %s\n", text);
113113

0 commit comments

Comments
 (0)