Skip to content

Zero-initialization using memset #691

@sim642

Description

@sim642

zstd uses memset to zero-initialize/reset some allocated structs. For example:

static void ZSTD_initCCtx(ZSTD_CCtx* cctx, ZSTD_customMem memManager)
{
    assert(cctx != NULL);
    ZSTD_memset(cctx, 0, sizeof(*cctx));
    cctx->customMem = memManager;
    cctx->bmi2 = ZSTD_cpuSupportsBmi2();
    {   size_t const err = ZSTD_CCtx_reset(cctx, ZSTD_reset_parameters);
        assert(!ZSTD_isError(err));
        (void)err;
    }
}

Currently Goblint completely invalidates the variable under memset, destroying all precision in the struct (especially if it's a global or an alloc variable).
Instead, memsetting to 0 (if the memset length equals the struct size) could be handled better to zero-initialize the abstract value, a la calloc.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions