Skip to content

Storing va_args in a structure might be unsafe on some platforms #54

@an-dr

Description

@an-dr

Found during #41. On Linux it causes a segfault if used by more than one callback:

Program received signal SIGSEGV, Segmentation fault.
__strlen_avx2 () at ../sysdeps/x86_64/multiarch/strlen-avx2.S:74
74      ../sysdeps/x86_64/multiarch/strlen-avx2.S: No such file or directory

AI explanation:

No, you cannot safely store a va_list in a structure to be reused by multiple callbacks in C++ (or C), because:

va_list is only valid during the lifetime of the original va_start/va_end block. Accessing it outside this scope leads to undefined behavior.

On some platforms, va_list is not just a pointer, but may involve internal state (e.g. stack frame information or special CPU registers), so copying or storing it across function boundaries can break.

Metadata

Metadata

Assignees

No one assigned

    Labels

    🐞 bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions