summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authoralbert-github <albert.tests@gmail.com>2019-05-06 09:49:41 (GMT)
committeralbert-github <albert.tests@gmail.com>2019-05-06 09:49:41 (GMT)
commit2d46a052563c1d362bfe4fa3c8fac1a258ce4cc2 (patch)
tree2626a684792a76a5f317e8b29c1a3791d80eb2fb /src
parentc637dede9ec30c2e35f19636edc0b3fd424b45e5 (diff)
downloadDoxygen-2d46a052563c1d362bfe4fa3c8fac1a258ce4cc2.zip
Doxygen-2d46a052563c1d362bfe4fa3c8fac1a258ce4cc2.tar.gz
Doxygen-2d46a052563c1d362bfe4fa3c8fac1a258ce4cc2.tar.bz2
Truncated warning message
In case of extremely long warning messages (e.g. in case of overloaded methods with a lot of alternatives) the warning message is truncated due to the "limited" buffer size. By using `vsnprintf(NULL, 0, fmt, args)` it is possible to determine the length of the message based on format and actual arguments. `char text[bufSize]` cannot be used as some older compilers don't accept it. (reference: https://stackoverflow.com/questions/3919995/determining-sprintf-buffer-size-whats-the-standard/30909417#30909417)
Diffstat (limited to 'src')
-rw-r--r--src/message.cpp14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/message.cpp b/src/message.cpp
index 2f3a06f..2e3e41a 100644
--- a/src/message.cpp
+++ b/src/message.cpp
@@ -167,17 +167,25 @@ static void format_warn(const char *file,int line,const char *text)
static void do_warn(bool enabled, const char *file, int line, const char *prefix, const char *fmt, va_list args)
{
if (!enabled) return; // warning type disabled
- const int bufSize = 40960;
- char text[bufSize];
int l=0;
if (prefix)
{
- qstrncpy(text,prefix,bufSize);
l=strlen(prefix);
}
+ // determine needed buffersize based on:
+ // format + arguments
+ // prefix
+ // 1 position for `\0`
+ int bufSize = vsnprintf(NULL, 0, fmt, args) + l + 1;
+ char *text = (char *)malloc(sizeof(char) * bufSize);
+ if (prefix)
+ {
+ qstrncpy(text,prefix,bufSize);
+ }
vsnprintf(text+l, bufSize-l, fmt, args);
text[bufSize-1]='\0';
format_warn(file,line,text);
+ free(text);
}
void warn(const char *file,int line,const char *fmt, ...)