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

Replace trailing 1-element arrays with C99 flex-arrays #3785

Closed
wants to merge 1 commit into from

Commits on Oct 7, 2023

  1. Replace trailing 1-element arrays with C99 flex-arrays

    Using a trailing 1-element array as a variable-length array is undefined
    behavior.  Compilers have traditionally allowed this, as this is a
    traditional, pre-C99 convention.  But it's being increasingly phased out
    in favor of C99 flexible arrays, which avoid ambiguity about whether the
    array is intended to be variable-length or not.  gcc 13+ and clang 16+
    support the -fstrict-flex-arrays=3 option, which Linux v6.5+ enables
    globally, resulting in UBSAN errors when these arrays are accessed.
    (See https://lore.kernel.org/r/00000000000049964e06041f2cbf@google.com)
    
    Fix this by making zstd use C99 flexible arrays instead of 1-element
    arrays.  This only affects three places (that I could find): one in
    fse_decompress.c and two in zstdmt_compress.c.
    
    Note, this breaks the c89build CI job and thus might not be suitable for
    merging yet.  I recommend that zstd drop support for C89/C90.
    ebiggers committed Oct 7, 2023
    Configuration menu
    Copy the full SHA
    c0bedaf View commit details
    Browse the repository at this point in the history