Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zero-initialization using memset #691

Closed
sim642 opened this issue Apr 19, 2022 · 1 comment · Fixed by #696
Closed

Zero-initialization using memset #691

sim642 opened this issue Apr 19, 2022 · 1 comment · Fixed by #696
Assignees
Milestone

Comments

@sim642
Copy link
Member

sim642 commented Apr 19, 2022

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.

@sim642
Copy link
Member Author

sim642 commented Apr 27, 2022

Just to document it here, after the merge I also extended it to bzero and friends analogously (where the written value is 0 by construction).

@sim642 sim642 added this to the v2.0.0 milestone Aug 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant