Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
In xbt_log_layout_simple_doit, add missing calls to check_overflow.
authorArnaud Giersch <arnaud.giersch@iut-bm.univ-fcomte.fr>
Tue, 25 Oct 2011 20:56:57 +0000 (22:56 +0200)
committerArnaud Giersch <arnaud.giersch@iut-bm.univ-fcomte.fr>
Fri, 28 Oct 2011 14:18:33 +0000 (16:18 +0200)
Also keep room for the final '\0'.

src/xbt/xbt_log_layout_format.c
src/xbt/xbt_log_layout_simple.c

index f7ca02d..67ab93d 100644 (file)
@@ -204,10 +204,10 @@ static void xbt_log_layout_format_dynamic(xbt_log_layout_t l,
 
 #undef check_overflow
 #define check_overflow \
 
 #undef check_overflow
 #define check_overflow \
-  if (p-ev->buffer > XBT_LOG_BUFF_SIZE) { /* buffer overflow */ \
-  xbt_log_layout_format_dynamic(l,ev,msg_fmt,app); \
-  return;\
-  }
+  if (p - ev->buffer >= XBT_LOG_BUFF_SIZE) { /* buffer overflow */ \
+    xbt_log_layout_format_dynamic(l,ev,msg_fmt,app);               \
+    return;                                                        \
+  } else ((void)0)
 
 #define show_it(data,letter) \
   do { \
 
 #define show_it(data,letter) \
   do { \
index f6a09be..26de2a0 100644 (file)
@@ -59,10 +59,10 @@ static void xbt_log_layout_simple_dynamic(xbt_log_layout_t l,
 /* only used after the format using: we suppose that the buffer is big enough to display our data */
 #undef check_overflow
 #define check_overflow \
 /* only used after the format using: we suppose that the buffer is big enough to display our data */
 #undef check_overflow
 #define check_overflow \
-  if (p-ev->buffer > XBT_LOG_BUFF_SIZE) { /* buffer overflow */ \
-  xbt_log_layout_simple_dynamic(l,ev,fmt,app); \
-  return; \
-  }
+  if (p - ev->buffer >= XBT_LOG_BUFF_SIZE) { /* buffer overflow */ \
+    xbt_log_layout_simple_dynamic(l,ev,fmt,app);                   \
+    return;                                                        \
+  } else ((void)0)
 
 static void xbt_log_layout_simple_doit(xbt_log_layout_t l,
                                        xbt_log_event_t ev,
 
 static void xbt_log_layout_simple_doit(xbt_log_layout_t l,
                                        xbt_log_event_t ev,
@@ -95,13 +95,16 @@ static void xbt_log_layout_simple_doit(xbt_log_layout_t l,
   check_overflow;
 
   /* Display file position if not INFO */
   check_overflow;
 
   /* Display file position if not INFO */
-  if (ev->priority != xbt_log_priority_info && !xbt_log_no_loc)
+  if (ev->priority != xbt_log_priority_info && !xbt_log_no_loc) {
     p += snprintf(p, XBT_LOG_BUFF_SIZE - (p - ev->buffer), "%s:%d: ",
                   ev->fileName, ev->lineNum);
     p += snprintf(p, XBT_LOG_BUFF_SIZE - (p - ev->buffer), "%s:%d: ",
                   ev->fileName, ev->lineNum);
+    check_overflow;
+  }
 
   /* Display category name */
   p += snprintf(p, XBT_LOG_BUFF_SIZE - (p - ev->buffer), "[%s/%s] ",
                 ev->cat->name, xbt_log_priority_names[ev->priority]);
 
   /* Display category name */
   p += snprintf(p, XBT_LOG_BUFF_SIZE - (p - ev->buffer), "[%s/%s] ",
                 ev->cat->name, xbt_log_priority_names[ev->priority]);
+  check_overflow;
 
   /* Display user-provided message */
   p += vsnprintf(p, XBT_LOG_BUFF_SIZE - (p - ev->buffer), fmt, ev->ap);
 
   /* Display user-provided message */
   p += vsnprintf(p, XBT_LOG_BUFF_SIZE - (p - ev->buffer), fmt, ev->ap);