From 836d57176dc699a726c55418e4f96b8ca628e1bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20Gallou=C3=ABt?= Date: Sat, 3 Oct 2026 19:47:54 +0200 Subject: [PATCH] mtmd : fix deprecated strdup warning on Windows (#29863) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Adrien Gallouët --- tools/mtmd/mtmd-helper.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/tools/mtmd/mtmd-helper.cpp b/tools/mtmd/mtmd-helper.cpp index cd05ade2d7..eba034f79e 100644 --- a/tools/mtmd/mtmd-helper.cpp +++ b/tools/mtmd/mtmd-helper.cpp @@ -516,6 +516,16 @@ bool mtmd_helper_support_video(const mtmd_context * ctx) { #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 { const mtmd_context * mctx; std::string path; @@ -799,7 +809,7 @@ struct mtmd_helper_video { *out_text = nullptr; if (!pending_text.empty()) { - *out_text = strdup(pending_text.c_str()); + *out_text = mtmd_strdup(pending_text); pending_text.clear(); return *out_text ? 0 : -2; } @@ -814,7 +824,7 @@ struct mtmd_helper_video { if (!start_emitted) { start_emitted = true; if (!prompt_start.empty()) { - *out_text = strdup(prompt_start.c_str()); + *out_text = mtmd_strdup(prompt_start); return *out_text ? 0 : -2; } }