diff --git a/src/snmalloc/backend_helpers/largebuddyrange.h b/src/snmalloc/backend_helpers/largebuddyrange.h index e85e06f21..803eb4844 100644 --- a/src/snmalloc/backend_helpers/largebuddyrange.h +++ b/src/snmalloc/backend_helpers/largebuddyrange.h @@ -6,8 +6,6 @@ #include "empty_range.h" #include "range_helpers.h" -#include - namespace snmalloc { /** diff --git a/src/snmalloc/ds/combininglock.h b/src/snmalloc/ds/combininglock.h index e5b79eaad..a62fb0b72 100644 --- a/src/snmalloc/ds/combininglock.h +++ b/src/snmalloc/ds/combininglock.h @@ -4,7 +4,6 @@ #include "../pal/pal.h" #include -#include namespace snmalloc { diff --git a/src/snmalloc/ds/flaglock.h b/src/snmalloc/ds/flaglock.h index cd314f90d..c711020d8 100644 --- a/src/snmalloc/ds/flaglock.h +++ b/src/snmalloc/ds/flaglock.h @@ -4,7 +4,6 @@ #include "../pal/pal.h" #include -#include namespace snmalloc { diff --git a/src/snmalloc/ds/singleton.h b/src/snmalloc/ds/singleton.h index 375a82f87..174128e77 100644 --- a/src/snmalloc/ds/singleton.h +++ b/src/snmalloc/ds/singleton.h @@ -3,9 +3,7 @@ #include "../ds_core/ds_core.h" #include "flaglock.h" -#include #include -#include #include namespace snmalloc diff --git a/src/snmalloc/ds_core/helpers.h b/src/snmalloc/ds_core/helpers.h index e79c56950..fa24f29c8 100644 --- a/src/snmalloc/ds_core/helpers.h +++ b/src/snmalloc/ds_core/helpers.h @@ -4,8 +4,8 @@ #include #include -#include #include +#include #include namespace snmalloc diff --git a/src/snmalloc/ds_core/redblacktree.h b/src/snmalloc/ds_core/redblacktree.h index 8b981aba9..59ad4c8db 100644 --- a/src/snmalloc/ds_core/redblacktree.h +++ b/src/snmalloc/ds_core/redblacktree.h @@ -3,7 +3,6 @@ #include #include #include -#include namespace snmalloc { @@ -439,9 +438,27 @@ namespace snmalloc depth); if (!(get_dir(true, curr).is_null() && get_dir(false, curr).is_null())) { - auto s_indent = std::string(indent); - print(get_dir(true, curr), (s_indent + "|").c_str(), depth + 1); - print(get_dir(false, curr), (s_indent + " ").c_str(), depth + 1); + // As the tree should be balanced, the depth should not exceed 128 if + // there are 2^64 elements in the tree. This is a debug feature, and + // it would be impossible to debug something of this size, so this is + // considerably larger than required. + // If there is a bug that leads to an unbalanced tree, this might be + // insufficient to accurately display the tree, but it will still be + // memory safe as the search code is bounded by the string size. + static constexpr size_t max_depth = 128; + char s_indent[max_depth]; + size_t end = 0; + for (; end < max_depth - 1; end++) + { + if (indent[end] == 0) + break; + s_indent[end] = indent[end]; + } + s_indent[end] = '|'; + s_indent[end + 1] = 0; + print(get_dir(true, curr), s_indent, depth + 1); + s_indent[end] = ' '; + print(get_dir(false, curr), s_indent, depth + 1); } } } diff --git a/src/snmalloc/mem/freelist_queue.h b/src/snmalloc/mem/freelist_queue.h index e7dd813e1..fb38f7c88 100644 --- a/src/snmalloc/mem/freelist_queue.h +++ b/src/snmalloc/mem/freelist_queue.h @@ -3,7 +3,6 @@ #include "../ds/ds.h" #include "freelist.h" -#include #include namespace snmalloc diff --git a/src/snmalloc/mem/remoteallocator.h b/src/snmalloc/mem/remoteallocator.h index 0a72aa318..a207d12f2 100644 --- a/src/snmalloc/mem/remoteallocator.h +++ b/src/snmalloc/mem/remoteallocator.h @@ -2,6 +2,8 @@ #include "freelist_queue.h" +#include + namespace snmalloc { class RemoteMessageAssertions; diff --git a/src/snmalloc/pal/pal_consts.h b/src/snmalloc/pal/pal_consts.h index 3c7fd58db..5679c336e 100644 --- a/src/snmalloc/pal/pal_consts.h +++ b/src/snmalloc/pal/pal_consts.h @@ -3,7 +3,6 @@ #include "../ds_core/ds_core.h" #include -#include namespace snmalloc { diff --git a/src/snmalloc/pal/pal_ds.h b/src/snmalloc/pal/pal_ds.h index 3da37cf46..008d1f2c2 100644 --- a/src/snmalloc/pal/pal_ds.h +++ b/src/snmalloc/pal/pal_ds.h @@ -3,7 +3,6 @@ #include "../ds_core/ds_core.h" #include -#include namespace snmalloc { diff --git a/src/test/func/redblack/redblack.cc b/src/test/func/redblack/redblack.cc index f13c72ebb..40ce667c8 100644 --- a/src/test/func/redblack/redblack.cc +++ b/src/test/func/redblack/redblack.cc @@ -4,7 +4,6 @@ #include "test/xoroshiro.h" #include -#include #include #include diff --git a/src/test/perf/startup/startup.cc b/src/test/perf/startup/startup.cc index 437128f05..46e18f90d 100644 --- a/src/test/perf/startup/startup.cc +++ b/src/test/perf/startup/startup.cc @@ -3,6 +3,7 @@ #include "test/usage.h" #include "test/xoroshiro.h" +#include #include #include #include