From 03ebdf3fc6bf30fa93d5b0248f5a13b826f9f015 Mon Sep 17 00:00:00 2001 From: Fangjun Kuang Date: Wed, 26 Jun 2024 09:57:19 +0800 Subject: [PATCH] Fix possible segfault in C API. (#1059) --- sherpa-onnx/c-api/c-api.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sherpa-onnx/c-api/c-api.cc b/sherpa-onnx/c-api/c-api.cc index ef4034ec..9d70fb8a 100644 --- a/sherpa-onnx/c-api/c-api.cc +++ b/sherpa-onnx/c-api/c-api.cc @@ -222,7 +222,7 @@ const SherpaOnnxOnlineRecognizerResult *GetOnlineStreamResult( } r->tokens_arr = tokens_temp; - if (!result.timestamps.empty()) { + if (!result.timestamps.empty() && result.timestamps.size() == r->count) { r->timestamps = new float[r->count]; std::copy(result.timestamps.begin(), result.timestamps.end(), r->timestamps); @@ -490,7 +490,7 @@ const SherpaOnnxOfflineRecognizerResult *GetOfflineStreamResult( } r->tokens_arr = tokens_temp; - if (!result.timestamps.empty()) { + if (!result.timestamps.empty() && result.timestamps.size() == r->count) { r->timestamps = new float[r->count]; std::copy(result.timestamps.begin(), result.timestamps.end(), r->timestamps);