Skip to content
DebugAllocatorInitWith

DebugAllocatorInitWith

Description

Construct a DebugAllocator with caller-supplied DebugAllocatorConfig. Use when you want to opt into force_page_backing or otherwise tune trace depth / canary width / freed-history retention away from the DEBUG_ALLOCATOR_DEFAULTS baseline. Captures the calling thread’s identifier at expansion so subsequent entry points can enforce the single-threaded contract.

_cfg is evaluated once.

Success

Returns a fully-initialised DebugAllocator value with the supplied config; the embedded heap / meta / page backing allocators are initialised but lazy (no OS calls yet); creator_tid is set to the calling thread.

Failure

Cannot fail at macro-expansion time.

Usage example (Cross-references)

Usage examples (Cross-references)
    #    if FEATURE_DEFAULT_ALLOC_DEBUG_PAGE_BACKED
    #        define DefaultAllocatorInit()                                                                                 \
                DebugAllocatorInitWith(((DebugAllocatorConfig) {.capture_traces      = true,                               \
                                                                .detect_overflow     = true,                               \
                                                                .force_page_backing  = true,                               \
    /// TAGS: Allocator, Debug, Init
    ///
    #define DebugAllocatorInit() DebugAllocatorInitWith(DEBUG_ALLOCATOR_DEFAULTS)
    
    #endif // MISRA_STD_ALLOCATOR_DEBUG_H
        DebugAllocatorConfig cfg = DEBUG_ALLOCATOR_DEFAULTS;
        cfg.track_freed_history  = false;
        DebugAllocator dbg       = DebugAllocatorInitWith(cfg);
        Allocator     *adbg      = ALLOCATOR_OF(&dbg);
        DebugAllocatorConfig cfg = DEBUG_ALLOCATOR_DEFAULTS;
        cfg.force_page_backing   = true;
        DebugAllocator dbg       = DebugAllocatorInitWith(cfg);
        Allocator     *adbg      = ALLOCATOR_OF(&dbg);
        DebugAllocatorConfig cfg = DEBUG_ALLOCATOR_DEFAULTS;
        cfg.capture_traces       = false;
        DebugAllocator dbg       = DebugAllocatorInitWith(cfg);
        Allocator     *adbg      = ALLOCATOR_OF(&dbg);
        DebugAllocatorConfig cfg = DEBUG_ALLOCATOR_DEFAULTS;
        cfg.trace_depth          = 2;
        DebugAllocator dbg       = DebugAllocatorInitWith(cfg);
        Allocator     *adbg      = ALLOCATOR_OF(&dbg);
        DebugAllocatorConfig cfg = DEBUG_ALLOCATOR_DEFAULTS;
        cfg.trace_depth          = 20;
        DebugAllocator dbg       = DebugAllocatorInitWith(cfg);
        Allocator     *adbg      = ALLOCATOR_OF(&dbg);
        DebugAllocatorConfig cfg = DEBUG_ALLOCATOR_DEFAULTS;
        cfg.trace_depth          = 4; // below MAX_TRACE
        DebugAllocator dbg       = DebugAllocatorInitWith(cfg);
        Allocator     *adbg      = ALLOCATOR_OF(&dbg);
        DebugAllocatorConfig cfg = DEBUG_ALLOCATOR_DEFAULTS;
        cfg.trace_depth          = 32; // above MAX_TRACE -> must clamp to 16
        DebugAllocator dbg       = DebugAllocatorInitWith(cfg);
        Allocator     *adbg      = ALLOCATOR_OF(&dbg);
        cfg.capture_traces       = true;
        cfg.trace_depth          = 32; // above DEBUG_ALLOCATOR_MAX_TRACE (16)
        DebugAllocator dbg       = DebugAllocatorInitWith(cfg);
        Allocator     *adbg      = ALLOCATOR_OF(&dbg);
    static DebugAllocator make_lean_debug_allocator(void) {
        DebugAllocatorConfig cfg = {.capture_traces = false, .detect_overflow = false, .track_freed_history = false};
        return DebugAllocatorInitWith(cfg);
    }
    
    bool test_compare_abs_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
    
        Float a = FloatFromStr("1.5", &dbg.base);
    // float_compare_int_with_error  [773:5]
    bool test_compare_int_rhs_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Float          a   = FloatFromStr("3.5", &dbg.base);
        Int            b   = IntFrom(3, &dbg.base);
    // float_compare_u64_with_error  [798:5]
    bool test_compare_u64_rhs_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Float          a   = FloatFromStr("3.5", &dbg.base);
    // float_compare_i64_with_error  [823:5]
    bool test_compare_i64_rhs_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Float          a   = FloatFromStr("-3.5", &dbg.base);
    // float_compare_f32_with_error  [848:5]
    bool test_compare_f32_rhs_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Float          a   = FloatFromStr("3.5", &dbg.base);
    // float_compare_f64_with_error  [873:5]
    bool test_compare_f64_rhs_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Float          a   = FloatFromStr("3.5", &dbg.base);
    
    bool test_add_scaling_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
    
        Float a = FloatFromStr("1.5", &dbg.base);   // exp -1
    
    bool test_add_replace_prepopulated_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
    
        Float a = FloatFromStr("2.5", &dbg.base);
    
    bool test_add_cancel_to_zero_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
    
        Float a = FloatFromStr("7.25", &dbg.base);
    
    bool test_div_success_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
    
        Float a = FloatFromStr("1", &dbg.base);
    
    bool test_div_zero_dividend_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
    
        Float a = FloatFrom(0u, &dbg.base);
    
    bool test_mul_replace_prepopulated_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
    
        Float a = FloatFromStr("2.5", &dbg.base);
    // float_add_int  [970:5]
    bool test_add_int_rhs_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Float          a   = FloatFromStr("1.5", &dbg.base);
        Float          r   = FloatInit(&dbg.base);
    // float_add_u64  [981:5]
    bool test_add_u64_rhs_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Float          a   = FloatFromStr("1.5", &dbg.base);
        Float          r   = FloatInit(&dbg.base);
    // float_add_i64  [992:5]
    bool test_add_i64_rhs_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Float          a   = FloatFromStr("1.5", &dbg.base);
        Float          r   = FloatInit(&dbg.base);
    // float_add_f32  [1003:5]
    bool test_add_f32_rhs_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Float          a   = FloatFromStr("1.5", &dbg.base);
        Float          r   = FloatInit(&dbg.base);
    // float_add_f64  [1014:5]
    bool test_add_f64_rhs_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Float          a   = FloatFromStr("1.5", &dbg.base);
        Float          r   = FloatInit(&dbg.base);
    // float_sub (Float*Float): FloatDeinit(&rhs) negated clone  [1030:5]
    bool test_sub_float_rhs_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Float          a   = FloatFromStr("5.5", &dbg.base);
        Float          b   = FloatFromStr("1.25", &dbg.base);
    // float_sub_int  [1041:5]
    bool test_sub_int_rhs_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Float          a   = FloatFromStr("5.5", &dbg.base);
        Float          r   = FloatInit(&dbg.base);
    // float_sub_u64  [1052:5]
    bool test_sub_u64_rhs_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Float          a   = FloatFromStr("5.5", &dbg.base);
        Float          r   = FloatInit(&dbg.base);
    // float_sub_i64  [1063:5]
    bool test_sub_i64_rhs_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Float          a   = FloatFromStr("5.5", &dbg.base);
        Float          r   = FloatInit(&dbg.base);
    // float_sub_f32  [1074:5]
    bool test_sub_f32_rhs_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Float          a   = FloatFromStr("5.5", &dbg.base);
        Float          r   = FloatInit(&dbg.base);
    // float_sub_f64  [1085:5]
    bool test_sub_f64_rhs_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Float          a   = FloatFromStr("5.5", &dbg.base);
        Float          r   = FloatInit(&dbg.base);
    // float_mul_int  [1115:5]
    bool test_mul_int_rhs_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Float          a   = FloatFromStr("1.5", &dbg.base);
        Float          r   = FloatInit(&dbg.base);
    // float_mul_u64  [1126:5]
    bool test_mul_u64_rhs_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Float          a   = FloatFromStr("1.5", &dbg.base);
        Float          r   = FloatInit(&dbg.base);
    // float_mul_i64  [1137:5]
    bool test_mul_i64_rhs_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Float          a   = FloatFromStr("1.5", &dbg.base);
        Float          r   = FloatInit(&dbg.base);
    // float_mul_f32  [1148:5]
    bool test_mul_f32_rhs_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Float          a   = FloatFromStr("1.5", &dbg.base);
        Float          r   = FloatInit(&dbg.base);
    // float_mul_f64  [1159:5]
    bool test_mul_f64_rhs_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Float          a   = FloatFromStr("1.5", &dbg.base);
        Float          r   = FloatInit(&dbg.base);
    // float_div_int  [1216:5]
    bool test_div_int_rhs_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Float          a   = FloatFromStr("1", &dbg.base);
        Float          r   = FloatInit(&dbg.base);
    // float_div_u64  [1228:5]
    bool test_div_u64_rhs_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Float          a   = FloatFromStr("1", &dbg.base);
        Float          r   = FloatInit(&dbg.base);
    // float_div_i64  [1240:5]
    bool test_div_i64_rhs_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Float          a   = FloatFromStr("1", &dbg.base);
        Float          r   = FloatInit(&dbg.base);
    // float_div_f32  [1252:5]
    bool test_div_f32_rhs_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Float          a   = FloatFromStr("1", &dbg.base);
        Float          r   = FloatInit(&dbg.base);
    // float_div_f64  [1264:5]
    bool test_div_f64_rhs_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Float          a   = FloatFromStr("1", &dbg.base);
        Float          r   = FloatInit(&dbg.base);
    
    bool test_from_f64_negative_binexp_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
    
        Float v = FloatFrom(0.5, &dbg.base); // binexp < 0 -> 5^|binexp| path
    
    bool test_from_f32_negative_binexp_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
    
        Float v = FloatFrom(1.5f, &dbg.base); // binexp < 0 -> 5^|binexp| path
    
    bool test_normalize_trailing_zeros_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
    
        Float v = FloatFrom(1000u, &dbg.base); // 1000 -> significand 1, exp 3
    
    bool test_pow10_success_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
    
        Float v = FloatFromStr("1e3", &dbg.base); // exponent 3 > 0 -> pow10
    
    bool test_to_int_positive_exponent_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
    
        Float v = FloatFromStr("12e4", &dbg.base); // significand 12, exp 4
    
    bool test_to_int_negative_exponent_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
    
        Float v = FloatFromStr("150e-1", &dbg.base); // 15.0, exact integer 15
    
    bool test_to_int_negative_exponent_factor_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
    
        Float v = FloatFromStr("1.5", &dbg.base); // significand 15, exponent -1
    
    bool test_to_int_zero_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
    
        Float v = FloatFrom(0u, &dbg.base);
    
    bool test_to_str_fractional_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
    
        Float v   = FloatFromStr("12.5", &dbg.base);
    
    bool test_to_str_integer_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
    
        Float v   = FloatFromStr("1200", &dbg.base); // exponent >= 0 arm
    
    bool test_from_str_prepopulated_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
    
        Float v = FloatFromStr("99999", &dbg.base); // pre-populated target
        WriteFmt("Testing BitVecRotateLeft frees its temp clone (1131:5)\n");
    
        DebugAllocator dbg  = DebugAllocatorInitWith(lean_dbg_cfg());
        Allocator     *adbg = ALLOCATOR_OF(&dbg);
        WriteFmt("Testing bitvec_regex_match_zstr frees its rendered Str (1866:5)\n");
    
        DebugAllocator dbg  = DebugAllocatorInitWith(lean_dbg_cfg());
        Allocator     *adbg = ALLOCATOR_OF(&dbg);
        WriteFmt("Testing bitvec_regex_match_str frees its rendered Str (1883:5)\n");
    
        DebugAllocator dbg  = DebugAllocatorInitWith(lean_dbg_cfg());
        Allocator     *adbg = ALLOCATOR_OF(&dbg);
    
    bool test_mul_nonzero_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Allocator     *a   = ALLOCATOR_OF(&dbg);
    
    bool test_mul_zero_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Allocator     *a   = ALLOCATOR_OF(&dbg);
    
    bool test_add_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Allocator     *a   = ALLOCATOR_OF(&dbg);
    
    bool test_sub_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Allocator     *a   = ALLOCATOR_OF(&dbg);
    
    bool test_add_u64_in_place_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Allocator     *a   = ALLOCATOR_OF(&dbg);
    
    bool test_mul_u64_in_place_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Allocator     *a   = ALLOCATOR_OF(&dbg);
    
    bool test_sub_u64_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Allocator     *a   = ALLOCATOR_OF(&dbg);
    
    bool test_div_mod_ge_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Allocator     *a   = ALLOCATOR_OF(&dbg);
    
    bool test_div_mod_lt_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Allocator     *a   = ALLOCATOR_OF(&dbg);
    
    bool test_div_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Allocator     *a   = ALLOCATOR_OF(&dbg);
    
    bool test_div_exact_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Allocator     *a   = ALLOCATOR_OF(&dbg);
    
    bool test_div_scalar_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Allocator     *a   = ALLOCATOR_OF(&dbg);
    
    bool test_div_mod_scalar_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Allocator     *a   = ALLOCATOR_OF(&dbg);
    
    bool test_mod_int_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Allocator     *a   = ALLOCATOR_OF(&dbg);
    
    bool test_pow_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Allocator     *a   = ALLOCATOR_OF(&dbg);
    
    bool test_gcd_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Allocator     *a   = ALLOCATOR_OF(&dbg);
    
    bool test_lcm_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Allocator     *a   = ALLOCATOR_OF(&dbg);
    
    bool test_root_rem_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Allocator     *a   = ALLOCATOR_OF(&dbg);
    
    bool test_root_rem_inexact_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Allocator     *a   = ALLOCATOR_OF(&dbg);
    
    bool test_root_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Allocator     *a   = ALLOCATOR_OF(&dbg);
    
    bool test_is_perfect_square_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Allocator     *a   = ALLOCATOR_OF(&dbg);
    
    bool test_is_perfect_power_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Allocator     *a   = ALLOCATOR_OF(&dbg);
    
    bool test_jacobi_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Allocator     *a   = ALLOCATOR_OF(&dbg);
    
    bool test_mod_add_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Allocator     *a   = ALLOCATOR_OF(&dbg);
    
    bool test_mod_sub_ge_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Allocator     *a   = ALLOCATOR_OF(&dbg);
    
    bool test_mod_sub_lt_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Allocator     *a   = ALLOCATOR_OF(&dbg);
    
    bool test_mod_sub_zero_diff_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Allocator     *a   = ALLOCATOR_OF(&dbg);
    
    bool test_mod_mul_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Allocator     *a   = ALLOCATOR_OF(&dbg);
    
    bool test_square_mod_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Allocator     *a   = ALLOCATOR_OF(&dbg);
    
    bool test_mod_div_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Allocator     *a   = ALLOCATOR_OF(&dbg);
    
    bool test_pow_u64_mod_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Allocator     *a   = ALLOCATOR_OF(&dbg);
    
    bool test_pow_mod_integer_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Allocator     *a   = ALLOCATOR_OF(&dbg);
    
    bool test_mod_inv_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Allocator     *a   = ALLOCATOR_OF(&dbg);
    
    bool test_mod_inv_negative_t_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Allocator     *a   = ALLOCATOR_OF(&dbg);
    
    bool test_mod_inv_no_solution_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Allocator     *a   = ALLOCATOR_OF(&dbg);
    
    bool test_mod_sqrt_p3mod4_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Allocator     *a   = ALLOCATOR_OF(&dbg);
    
    bool test_mod_sqrt_tonelli_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Allocator     *a   = ALLOCATOR_OF(&dbg);
    
    bool test_mod_sqrt_tonelli_larger_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Allocator     *a   = ALLOCATOR_OF(&dbg);
    
    bool test_mod_sqrt_zero_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Allocator     *a   = ALLOCATOR_OF(&dbg);
    
    bool test_mod_sqrt_mod2_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Allocator     *a   = ALLOCATOR_OF(&dbg);
    
    bool test_mod_sqrt_no_solution_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Allocator     *a   = ALLOCATOR_OF(&dbg);
    
    bool test_mod_sqrt_composite_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Allocator     *a   = ALLOCATOR_OF(&dbg);
    
    bool test_mod_sqrt_even_modulus_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Allocator     *a   = ALLOCATOR_OF(&dbg);
    
    bool test_is_probable_prime_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Allocator     *a   = ALLOCATOR_OF(&dbg);
    
    bool test_is_probable_prime_witness_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Allocator     *a   = ALLOCATOR_OF(&dbg);
    
    bool test_next_prime_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Allocator     *a   = ALLOCATOR_OF(&dbg);
    
    bool test_next_prime_small_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Allocator     *a   = ALLOCATOR_OF(&dbg);
    
    bool test_mul_nonzero_nonempty_result_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Allocator     *a   = ALLOCATOR_OF(&dbg);
    
    bool test_div_exact_i64_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Allocator     *a   = ALLOCATOR_OF(&dbg);
    
    bool test_mod_sqrt_tonelli_inner_loop_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Allocator     *a   = ALLOCATOR_OF(&dbg);
    
    bool test_blind_mod_inv_correct(void) {
        DebugAllocator dbg   = DebugAllocatorInitWith(blind_cfg());
        Allocator     *alloc = ALLOCATOR_OF(&dbg);
    
    bool test_blind_mod_sqrt_tonelli(void) {
        DebugAllocator dbg   = DebugAllocatorInitWith(blind_cfg());
        Allocator     *alloc = ALLOCATOR_OF(&dbg);
    
    bool test_blind_mod_sqrt_fast_branch(void) {
        DebugAllocator dbg   = DebugAllocatorInitWith(blind_cfg());
        Allocator     *alloc = ALLOCATOR_OF(&dbg);
    
    bool test_blind_mod_sub_branches(void) {
        DebugAllocator dbg   = DebugAllocatorInitWith(blind_cfg());
        Allocator     *alloc = ALLOCATOR_OF(&dbg);
    
    bool test_blind_next_prime(void) {
        DebugAllocator dbg   = DebugAllocatorInitWith(blind_cfg());
        Allocator     *alloc = ALLOCATOR_OF(&dbg);
    
    bool test_blind_carmichael_is_composite(void) {
        DebugAllocator dbg   = DebugAllocatorInitWith(blind_cfg());
        Allocator     *alloc = ALLOCATOR_OF(&dbg);
    
    bool test_to_str_radix_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Allocator     *a   = ALLOCATOR_OF(&dbg);
    
    bool test_from_bytes_be_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
    
        u8  bytes[] = {0x01, 0x02, 0x03, 0x04};
    
    bool test_from_str_nonempty_out_no_leak(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Allocator     *a   = ALLOCATOR_OF(&dbg);
    
    bool test_blind_to_str_radix_big(void) {
        DebugAllocator dbg   = DebugAllocatorInitWith(blind_cfg());
        Allocator     *alloc = ALLOCATOR_OF(&dbg);
    
    #define LEAK_WRITE_PRELUDE()                                                                                           \
        DebugAllocator dbg  = DebugAllocatorInitWith(LEAK_CFG);                                                            \
        Allocator     *adbg = ALLOCATOR_OF(&dbg);                                                                          \
        Str            out  = StrInit(adbg);                                                                               \
        for (int i = 0; i < 8; ++i)
            StrPushBackR(&s, (char)0xAB);
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Str            out = StrInit(ALLOCATOR_OF(&dbg));
        bool           ok  = StrAppendFmt(&out, "{x}", s) && (StrLen(&out) > 0);
    // ---------------------------------------------------------------------------
    bool test_leak_sci_nonzero_digits_freed(void) {
        DebugAllocator dbg  = DebugAllocatorInitWith(LEAK_CFG);
        Allocator     *adbg = ALLOCATOR_OF(&dbg);
    // ---------------------------------------------------------------------------
    bool test_leak_sci_zero_digits_freed(void) {
        DebugAllocator dbg  = DebugAllocatorInitWith(LEAK_CFG);
        Allocator     *adbg = ALLOCATOR_OF(&dbg);
    // ---------------------------------------------------------------------------
    bool test_leak_decimal_withdot_canonical_freed(void) {
        DebugAllocator dbg  = DebugAllocatorInitWith(LEAK_CFG);
        Allocator     *adbg = ALLOCATOR_OF(&dbg);
    // ---------------------------------------------------------------------------
    bool test_leak_decimal_nodot_canonical_freed(void) {
        DebugAllocator dbg  = DebugAllocatorInitWith(LEAK_CFG);
        Allocator     *adbg = ALLOCATOR_OF(&dbg);
    // ---------------------------------------------------------------------------
    bool test_leak_write_zstr_hex_per_byte_freed(void) {
        DebugAllocator dbg  = DebugAllocatorInitWith(LEAK_CFG);
        Allocator     *adbg = ALLOCATOR_OF(&dbg);
    // ---------------------------------------------------------------------------
    bool test_leak_write_i64_temp_freed(void) {
        DebugAllocator dbg  = DebugAllocatorInitWith(LEAK_CFG);
        Allocator     *adbg = ALLOCATOR_OF(&dbg);
    // closing quote -> unterminated-quote branch frees the destination Str.
    static bool leak_quoted_unterminated(Zstr input, Zstr fmt) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Str            s   = StrInit(ALLOCATOR_OF(&dbg));
        Zstr           p   = input;
    // scratch (allocated through the destination BitVec's allocator).
    static bool leak_bitvec_overflow(Zstr input) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        BitVec         bv  = BitVecInit(ALLOCATOR_OF(&dbg));
        Zstr           p   = input;
    // 2439: unquoted invalid-escape error path frees the destination Str.
    bool test_leak_read_unquoted_bad_escape_freed(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Str            s   = StrInit(ALLOCATOR_OF(&dbg));
        Zstr           p   = "aaaaaaaaaaaaaaaaaaaaaaaa\\q"; // 24 'a' + invalid \q
    // exponent overflow -> fail branch frees the internal `temp` scratch.
    bool test_leak_read_float_exp_overflow_freed(void) {
        DebugAllocator dbg = DebugAllocatorInitWith(LEAK_CFG);
        Float          fv  = FloatInit(ALLOCATOR_OF(&dbg));
        Zstr           p   = "1e99999999999999999999999999999999999999999999999999";
    // ---------------------------------------------------------------------------
    bool test_leak_read_int_prior_value_freed(void) {
        DebugAllocator dbg  = DebugAllocatorInitWith(LEAK_CFG);
        Allocator     *adbg = ALLOCATOR_OF(&dbg);
    // ---------------------------------------------------------------------------
    bool test_leak_read_float_prior_value_freed(void) {
        DebugAllocator dbg  = DebugAllocatorInitWith(LEAK_CFG);
        Allocator     *adbg = ALLOCATOR_OF(&dbg);
    // capture, no overflow canaries, no freed history -- just the live count.
    static DebugAllocator make_lean_dbg(void) {
        return DebugAllocatorInitWith(((DebugAllocatorConfig) {
            .capture_traces      = false,
            .detect_overflow     = false,
        cfg.detect_overflow      = false;
        cfg.track_freed_history  = false;
        return DebugAllocatorInitWith(cfg);
    }
    static DebugAllocator kv_lean_debug_allocator(void) {
        DebugAllocatorConfig cfg = {.capture_traces = false, .detect_overflow = false, .track_freed_history = false};
        return DebugAllocatorInitWith(cfg);
    }
Last updated on