opj_event_msg(): force zero termination of buffer

This commit is contained in:
Even Rouault 2017-07-30 19:27:01 +02:00
parent b716f86163
commit 9a6d41d22b
1 changed files with 3 additions and 5 deletions

View File

@ -121,16 +121,14 @@ OPJ_BOOL opj_event_msg(opj_event_mgr_t* p_event_mgr, OPJ_INT32 event_type,
if ((fmt != 00) && (p_event_mgr != 00)) { if ((fmt != 00) && (p_event_mgr != 00)) {
va_list arg; va_list arg;
size_t str_length/*, i, j*/; /* UniPG */
char message[OPJ_MSG_SIZE]; char message[OPJ_MSG_SIZE];
memset(message, 0, OPJ_MSG_SIZE); memset(message, 0, OPJ_MSG_SIZE);
/* initialize the optional parameter list */ /* initialize the optional parameter list */
va_start(arg, fmt); va_start(arg, fmt);
/* check the length of the format string */
str_length = (strlen(fmt) > OPJ_MSG_SIZE) ? OPJ_MSG_SIZE : strlen(fmt);
(void)str_length;
/* parse the format string and put the result in 'message' */ /* parse the format string and put the result in 'message' */
vsnprintf(message, OPJ_MSG_SIZE, fmt, arg); /* UniPG */ vsnprintf(message, OPJ_MSG_SIZE, fmt, arg);
/* force zero termination for Windows _vsnprintf() of old MSVC */
message[OPJ_MSG_SIZE - 1] = '\0';
/* deinitialize the optional parameter list */ /* deinitialize the optional parameter list */
va_end(arg); va_end(arg);