From d95880af931e9a7a72a275098d16a2b4f18fe82e Mon Sep 17 00:00:00 2001 From: Michael Catanzaro Date: Thu, 22 Aug 2024 12:48:00 -0500 Subject: [PATCH] ggettext: add some comments Coverity has improperly flagged this code as an instance of CWE-562. The code is fine, but it's confusing, and humans are likely to wind up examining it again in the future, so add some comments to explain what's up. --- glib/ggettext.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/glib/ggettext.c b/glib/ggettext.c index 21933d962..78b8e6487 100644 --- a/glib/ggettext.c +++ b/glib/ggettext.c @@ -237,6 +237,10 @@ g_dpgettext (const gchar *domain, translation = g_dgettext (domain, tmp); + /* g_dgettext() may return the value we pass to it, which will be on + * this stack frame since we allocated it with g_alloca(). If so, we + * return a pointer into our original input instead. + */ if (translation == tmp) return sep + 1; } @@ -294,6 +298,10 @@ g_dpgettext2 (const gchar *domain, msg_ctxt_id[msgctxt_len - 1] = '|'; translation = g_dgettext (domain, msg_ctxt_id); + /* g_dgettext() may return the value we pass to it, which will be on this + * stack frame since we allocated it with g_alloca(). If so, we return our + * original input instead. + */ if (translation == msg_ctxt_id) return msgid; }