summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--navit/debug.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/navit/debug.c b/navit/debug.c
index 3fd1c5386..d8277f761 100644
--- a/navit/debug.c
+++ b/navit/debug.c
@@ -308,14 +308,14 @@ debug_vprintf(dbg_level level, const char *module, const int mlen, const char *f
#if defined HAVE_API_WIN32_CE
#define vsnprintf _vsnprintf
#endif
- gchar *fmt_newline;
+ vsnprintf(debug_message+strlen(debug_message),sizeof(debug_message)-1-strlen(debug_message),fmt,ap);
#ifdef HAVE_API_WIN32_BASE
- fmt_newline = g_strconcat(fmt, "\r\n");
-#else
- fmt_newline = g_strconcat(fmt, "\n");
+ if (strlen(debug_message)<sizeof(debug_message))
+ debug_message[strlen(debug_message)] = '\r'; /* For Windows platforms, add \r at the end of the buffer (if any room) */
#endif
- vsnprintf(debug_message+strlen(debug_message),4095-strlen(debug_message),fmt_newline,ap);
- g_free(fmt_newline);
+ if (strlen(debug_message)<sizeof(debug_message))
+ debug_message[strlen(debug_message)] = '\n'; /* Add \n at the end of the buffer (if any room) */
+ debug_message[sizeof(debug_message)-1] = '\0'; /* Force NUL-termination of the string (if buffer size contraints did not allow for full string to fit */
#ifdef DEBUG_WIN32_CE_MESSAGEBOX
mbstowcs(muni, debug_message, strlen(debug_message)+1);
MessageBoxW(NULL, muni, TEXT("Navit - Error"), MB_APPLMODAL|MB_OK|MB_ICONERROR);