mtmd : fix deprecated strdup warning on Windows (#29863)

Signed-off-by: Adrien Gallouët <angt@huggingface.co>
This commit is contained in:
Adrien Gallouët
2026-10-03 19:47:54 +02:00
committed by GitHub
parent eec18f5d32
commit 836d57176d
+12 -2
View File
@@ -516,6 +516,16 @@ bool mtmd_helper_support_video(const mtmd_context * ctx) {
#ifdef MTMD_VIDEO #ifdef MTMD_VIDEO
// MSVC deprecates strdup(), use a std::string version directly
static char * mtmd_strdup(const std::string & s) {
size_t n = s.size() + 1;
char * p = (char *) malloc(n);
if (p) {
memcpy(p, s.c_str(), n);
}
return p;
}
struct mtmd_helper_video { struct mtmd_helper_video {
const mtmd_context * mctx; const mtmd_context * mctx;
std::string path; std::string path;
@@ -799,7 +809,7 @@ struct mtmd_helper_video {
*out_text = nullptr; *out_text = nullptr;
if (!pending_text.empty()) { if (!pending_text.empty()) {
*out_text = strdup(pending_text.c_str()); *out_text = mtmd_strdup(pending_text);
pending_text.clear(); pending_text.clear();
return *out_text ? 0 : -2; return *out_text ? 0 : -2;
} }
@@ -814,7 +824,7 @@ struct mtmd_helper_video {
if (!start_emitted) { if (!start_emitted) {
start_emitted = true; start_emitted = true;
if (!prompt_start.empty()) { if (!prompt_start.empty()) {
*out_text = strdup(prompt_start.c_str()); *out_text = mtmd_strdup(prompt_start);
return *out_text ? 0 : -2; return *out_text ? 0 : -2;
} }
} }