Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Make xbt_strbuff_chomp() really do its work.
[simgrid.git] / src / xbt / xbt_strbuff.c
index b12ff3c..a474b3a 100644 (file)
@@ -88,10 +88,9 @@ void xbt_strbuff_append(xbt_strbuff_t b, const char *toadd)
 
 XBT_INLINE void xbt_strbuff_chomp(xbt_strbuff_t b)
 {
-  while (b->data[b->used] == '\n') {
+  while (b->used && b->data[b->used - 1] == '\n') {
+    b->used--;
     b->data[b->used] = '\0';
-    if (b->used)
-      b->used--;
   }
 }