Skip to content

BufDeinit

Description

Release the backing storage of a Buf through its inline allocator.

Success

Returns to the caller. *b is zeroed.

Failure

Macro cannot fail. Safe on a zeroed Buf.

Usage example (Cross-references)

Usage examples (Cross-references)
        Buf data = BufInit(alloc);
        if (FileReadAndClose(path, &data) < 0) {
            BufDeinit(&data);
            LOG_ERROR("PeOpen: failed to read {}", path);
            return false;
        if (!self)
            return;
        BufDeinit(&self->data);
        VecDeinit(&self->sections);
        MemSet(self, 0, sizeof(*self));
        Buf data = BufInit(alloc);
        if (FileReadAndClose(path, &data) < 0) {
            BufDeinit(&data);
            LOG_ERROR("PdbOpen: failed to read {}", path);
            return false;
        StrDeinit(&self->name_pool);
        VecDeinit(&self->functions);
        BufDeinit(&self->data);
        MemSet(self, 0, sizeof(*self));
    }
        Buf data = BufInit(alloc);
        if (FileReadAndClose("/etc/localtime", &data) < 0) {
            BufDeinit(&data);
            LOG_ERROR("Tzif: cannot read /etc/localtime");
            return false;
        }
        bool ok = TzifOffsetFromBuf(BufData(&data), BufLength(&data), unix_seconds, out_offset_seconds);
        BufDeinit(&data);
        return ok;
    }
        Buf data = BufInit(alloc);
        if (FileReadAndClose(path, &data) < 0) {
            BufDeinit(&data);
            LOG_ERROR("MachoOpen: failed to read {}", path);
            return false;
        if (!self)
            return;
        BufDeinit(&self->data);
        VecDeinit(&self->segments);
        VecDeinit(&self->sections);
        Buf data = BufInit(alloc);
        if (FileReadAndClose(path, &data) < 0) {
            BufDeinit(&data);
            LOG_ERROR("ElfOpen: failed to read {}", path);
            return false;
        if (!self)
            return;
        BufDeinit(&self->data);
        VecDeinit(&self->sections);
        VecDeinit(&self->segments);
        ok = ok && (got == (i64)N) && (BufLength(&dst) == (size)N) && (MemCompare(BufData(&dst), BufData(&src), N) == 0);
    
        BufDeinit(&src);
        BufDeinit(&dst);
        FileRemove(&path);
    
        BufDeinit(&src);
        BufDeinit(&dst);
        FileRemove(&path);
        StrDeinit(&path);
    
        StrDeinit(&body);
        BufDeinit(&in);
        FileRemove(&path);
        StrDeinit(&path);
        BufClear(&b);
        ok = ok && BufLength(&b) == 0;
        BufDeinit(&b);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        };
        bool ok = BufLength(&b) == sizeof(expect) && MemCompare(BufData(&b), expect, sizeof(expect)) == 0;
        BufDeinit(&b);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        const u8 expect_uleb[] = {0x00, 0x7F, 0x80, 0x01, 0x80, 0x80, 0x01};
        if (BufLength(&b) != sizeof(expect_uleb) || MemCompare(BufData(&b), expect_uleb, sizeof(expect_uleb)) != 0) {
            BufDeinit(&b);
            DefaultAllocatorDeinit(&alloc);
            return false;
        bool ok = BufLength(&b) == sizeof(expect_sleb) && MemCompare(BufData(&b), expect_sleb, sizeof(expect_sleb)) == 0;
    
        BufDeinit(&b);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        const u8 expect[] = {'h', 'i', 0};
        bool     ok       = BufLength(&b) == sizeof(expect) && MemCompare(BufData(&b), expect, sizeof(expect)) == 0;
        BufDeinit(&b);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        ok         = ok && IterRemainingLength(&it) == 0;
    
        BufDeinit(&b);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        ok         = ok && IterRemainingLength(&it) == 0;
    
        BufDeinit(&b);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        ok         = ok && IterRemainingLength(&it) == 0;
    
        BufDeinit(&b);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        const u8 expect[] = {0x99, 0xFE, 0xCA, 0xDE, 0xAD, 0xBE, 0xEF};
        ok                = ok && BufLength(&b) == sizeof(expect) && MemCompare(BufData(&b), expect, sizeof(expect)) == 0;
        BufDeinit(&b);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        const u8 expect[] = {0x34, 0x12};
        ok                = ok && BufLength(&b) == sizeof(expect) && MemCompare(BufData(&b), expect, sizeof(expect)) == 0;
        BufDeinit(&b);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        ok = ok && BufLength(&b) == BufLength(&snapshot);
        ok = ok && MemCompare(BufData(&b), BufData(&snapshot), BufLength(&b)) == 0;
        BufDeinit(&snapshot);
    
        BufDeinit(&b);
        BufDeinit(&snapshot);
    
        BufDeinit(&b);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        ok         = ok && IterRemainingLength(&it) == 0;
    
        BufDeinit(&b);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        ok = ok && it.pos == entry && v32 == 0;
    
        BufDeinit(&b);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        bool ok = ZstrCompare(StrBegin(&output), "hello") == 0;
    
        BufDeinit(&b);
        StrDeinit(&output);
        DefaultAllocatorDeinit(&alloc);
        }
    
        BufDeinit(&b);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        }
    
        BufDeinit(&b);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        ok         = ok && BufReadFmt(&it, "{​{{>1r}", v) && (v == 0x41);
    
        BufDeinit(&b);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        }
    
        BufDeinit(&b);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        ok         = ok && rd && (v8 == 0x05);
    
        BufDeinit(&b);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        ok          = ok && rd && (v32 == 0xDEADBEEF);
    
        BufDeinit(&b);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        ok          = ok && rd && (v64 == 0x0102030405060708ULL);
    
        BufDeinit(&b);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        ok          = ok && rd && (v64 == -1234567890123LL);
    
        BufDeinit(&b);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        BufReadFmt(&it, "{2}", v16); // real: LOG_FATAL (non-raw). mutant: returns.
    
        BufDeinit(&b);
        DefaultAllocatorDeinit(&alloc);
        return true; // unreached on real code (aborts above)
        }
    
        BufDeinit(&b);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        }
    
        BufDeinit(&b);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        }
    
        BufDeinit(&b);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        const u8         expect[] = {0x7E};
        ok = ok && BufLength(&b) == sizeof(expect) && MemCompare(BufData(&b), expect, sizeof(expect)) == 0;
        BufDeinit(&b);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        const u8         expect[] = {0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01};
        ok = ok && BufLength(&b) == sizeof(expect) && MemCompare(BufData(&b), expect, sizeof(expect)) == 0;
        BufDeinit(&b);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        const u8 expect[] = {0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01};
        ok                = ok && BufLength(&b) == sizeof(expect) && MemCompare(BufData(&b), expect, sizeof(expect)) == 0;
        BufDeinit(&b);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        bool             ok    = BufWriteFmt(&b, "{<1r}", (u8)0xAB);
        ok                     = ok && (BufLength(&b) == 1) && (BufData(&b)[0] == 0xAB);
        BufDeinit(&b);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        Buf              b     = BufInit(&alloc);
        BufWriteFmt(&b, "{4}", (u32)0x11223344); // real: LOG_FATAL before return
        BufDeinit(&b);
        DefaultAllocatorDeinit(&alloc);
        return true;
        bool      ok = r && (BufLength(&b) == 4) && d[0] == 0xAA && d[1] == 0xBB && d[2] == 0xCC && d[3] == 0xDD;
    
        BufDeinit(&b);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        ok           = ok && (BufLength(&b) == 2) && d[0] == 0x12 && d[1] == 0x34;
    
        BufDeinit(&b);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        ok = ok && (BufLength(&b) == 2) && d[0] == 0x34 && d[1] == 0x12;
    
        BufDeinit(&b);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        ok           = ok && (BufLength(&b) == 4) && d[0] == 0x44 && d[1] == 0x33 && d[2] == 0x22 && d[3] == 0x11;
    
        BufDeinit(&b);
        DefaultAllocatorDeinit(&alloc);
        return ok;
             d[5] == 0x03 && d[6] == 0x02 && d[7] == 0x01;
    
        BufDeinit(&b);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        ok          = ok && (v64 == 0x0102030405060708ULL);
    
        BufDeinit(&b);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        ok            = ok && rd_ok && (v16 == 0x1234);
    
        BufDeinit(&b);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        u8      v8 = 0;
        BufReadFmt(&it, "{<1r}{<1r}", v8);                 // 2 fields, 1 arg -> abort
        BufDeinit(&b);
        DefaultAllocatorDeinit(&alloc);
        return true;
        u32     c              = 0;
        ok                     = ok && BufReadFmt(&it, "{<2r}{>4r}", a, c) && a == 0x1234 && c == 0xAABBCCDD;
        BufDeinit(&b);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        ok            = ok && rd_ok && (v32 == 0x12345678u);
    
        BufDeinit(&b);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        ok            = ok && rd_ok && (v32 == 0x12345678u);
    
        BufDeinit(&b);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        ok            = ok && rd_ok && (v32 == 0x78563412u);
    
        BufDeinit(&b);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        ok            = ok && rd_ok && (v32 == 0xAABBCCDDu);
    
        BufDeinit(&b);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        ok            = ok && rd_ok && (v64 == expected);
    
        BufDeinit(&b);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        ok            = ok && rd_ok && (v64 == expected);
    
        BufDeinit(&b);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        ok            = ok && rd_ok && (v64 == expected);
    
        BufDeinit(&b);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        ok          = ok && BufReadFmt(&it, "{<1r}", out) && (out == 0xAB);
    
        BufDeinit(&b);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        u16              v     = 0;
        ok                     = ok && BufReadFmt(&it, "{<2r}", v) && (v == 0xBEEF);
        BufDeinit(&b);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        BufIter it = BufIterFromBuf(&b);
        ok         = ok && BufReadFmt(&it, "{<8r}", got.f) && (got.u == 0x0102030405060708ULL);
        BufDeinit(&b);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        off     = 0;
        ok      = ok && resolve(&b, 2500000, &off) && off == -18000; // >= t1 -> STD
        BufDeinit(&b);
        DefaultAllocatorDeinit(&a);
        return ok;
        off     = 0;
        ok      = ok && resolve(&b, 2500000000, &off) && off == 19800; // >= t1 -> STD
        BufDeinit(&b);
        DefaultAllocatorDeinit(&a);
        return ok;
        i32  off = 0;
        bool ok  = TzifOffsetFromBuf(BufData(&b), BufLength(&b), 0, &off);
        BufDeinit(&b);
        DefaultAllocatorDeinit(&a);
        return ok && off == -18000;
        i32  off = 7;
        bool ok  = TzifOffsetFromBuf(BufData(&b), BufLength(&b), 0, &off);
        BufDeinit(&b);
        DefaultAllocatorDeinit(&a);
        return !ok;
        i32  off = 7;
        bool ok  = TzifOffsetFromBuf(BufData(&b), BufLength(&b), 0, &off);
        BufDeinit(&b);
        DefaultAllocatorDeinit(&a);
        return !ok;
Last updated on