diff --git a/src/gettext.h b/src/gettext.h --- a/src/gettext.h +++ b/src/gettext.h @@ -19,6 +19,8 @@ #ifndef _LIBGETTEXT_H #define _LIBGETTEXT_H 1 +#include + /* Get declarations of GNU message catalog functions. */ # include // libintl.h redefines inline which causes MSVC to abort compilation with the message @@ -112,7 +114,8 @@ const char *translation; int translation_found; #if _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS - char msg_ctxt_id[msgctxt_len + msgid_len]; + std::unique_ptr msg_ctxt_id(new char[msgctxt_len + msgid_len]); + memset(msg_ctxt_id.get(),'\n',msgctxt_len + msgid_len); #else char buf[1024]; char *msg_ctxt_id = @@ -122,12 +125,12 @@ if (msg_ctxt_id != nullptr) #endif { - memcpy(msg_ctxt_id, msgctxt, msgctxt_len - 1); + memcpy(msg_ctxt_id.get(), msgctxt, msgctxt_len - 1); msg_ctxt_id[msgctxt_len - 1] = '\004'; - memcpy(msg_ctxt_id + msgctxt_len, msgid, msgid_len); - translation = dgettext(domain, msg_ctxt_id); + memcpy(msg_ctxt_id.get() + msgctxt_len, msgid, msgid_len); + translation = dgettext(domain, msg_ctxt_id.get()); /* Test must occur before msg_ctxt_id freed */ - translation_found = translation != msg_ctxt_id; + translation_found = translation != msg_ctxt_id.get(); #if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS if (msg_ctxt_id != buf) { free(msg_ctxt_id); @@ -162,7 +165,8 @@ const char *translation; int translation_found; #if _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS - char msg_ctxt_id[msgctxt_len + msgid_len]; + std::unique_ptr msg_ctxt_id(new char[msgctxt_len + msgid_len]); + memset(msg_ctxt_id.get(),'\n',msgctxt_len + msgid_len); #else char buf[1024]; char *msg_ctxt_id = @@ -172,12 +176,12 @@ if (msg_ctxt_id != nullptr) #endif { - memcpy(msg_ctxt_id, msgctxt, msgctxt_len - 1); + memcpy(msg_ctxt_id.get(), msgctxt, msgctxt_len - 1); msg_ctxt_id[msgctxt_len - 1] = '\004'; - memcpy(msg_ctxt_id + msgctxt_len, msgid, msgid_len); - translation = dngettext(domain, msg_ctxt_id, msgid_plural, n); + memcpy(msg_ctxt_id.get() + msgctxt_len, msgid, msgid_len); + translation = dngettext(domain, msg_ctxt_id.get(), msgid_plural, n); /* Test must occur before msg_ctxt_id freed */ - translation_found = !(translation == msg_ctxt_id || translation == msgid_plural); + translation_found = !(translation == msg_ctxt_id.get() || translation == msgid_plural); #if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS if (msg_ctxt_id != buf) { free(msg_ctxt_id);