Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
MC: do not segfault when the logs are activated
[simgrid.git] / src / xbt / string.cpp
index 7872cdc..45f6348 100644 (file)
@@ -1,17 +1,15 @@
-/* Copyright (c) 2015-2017. The SimGrid Team.
- * All rights reserved.                                                     */
+/* Copyright (c) 2015-2022. The SimGrid Team. All rights reserved.          */
 
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
-#include <cstdarg>
-#include <cstdio>
-
-#include <simgrid_config.h>
-
+#include <simgrid/config.h>
 #include <xbt/string.hpp>
 #include <xbt/sysdep.h>
 
+#include <cstdarg>
+#include <cstdio>
+
 namespace simgrid {
 namespace xbt {
 
@@ -28,14 +26,13 @@ std::string string_vprintf(const char *fmt, va_list ap)
   va_copy(ap2, ap);
   int size = std::vsnprintf(nullptr, 0, fmt, ap2);
   va_end(ap2);
-  if (size < 0)
-    xbt_die("string_vprintf error");
+  xbt_assert(size >= 0, "string_vprintf error");
 
   // Allocate the string and format:
   std::string res;
   res.resize(size);
-  if (size != 0 && std::vsnprintf(&res[0], size + 1, fmt, ap) != size)
-    xbt_die("string_vprintf error");
+  if (size != 0)
+    xbt_assert(std::vsnprintf(&res[0], size + 1, fmt, ap) == size, "string_vprintf error");
   return res;
 }