Skip to content

Commit 9dfe88d

Browse files
authored
Fix possible segfault in C API. (k2-fsa#1059)
1 parent 3059eb1 commit 9dfe88d

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

sherpa-onnx/c-api/c-api.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ const SherpaOnnxOnlineRecognizerResult *GetOnlineStreamResult(
222222
}
223223
r->tokens_arr = tokens_temp;
224224

225-
if (!result.timestamps.empty()) {
225+
if (!result.timestamps.empty() && result.timestamps.size() == r->count) {
226226
r->timestamps = new float[r->count];
227227
std::copy(result.timestamps.begin(), result.timestamps.end(),
228228
r->timestamps);
@@ -490,7 +490,7 @@ const SherpaOnnxOfflineRecognizerResult *GetOfflineStreamResult(
490490
}
491491
r->tokens_arr = tokens_temp;
492492

493-
if (!result.timestamps.empty()) {
493+
if (!result.timestamps.empty() && result.timestamps.size() == r->count) {
494494
r->timestamps = new float[r->count];
495495
std::copy(result.timestamps.begin(), result.timestamps.end(),
496496
r->timestamps);

0 commit comments

Comments
 (0)