Skip to content

Add nonstring attribute to fix Clang build errors#282

Merged
mutability merged 1 commit intoflightaware:devfrom
zfogg:fix/nonstring-attribute-warnings
Mar 25, 2026
Merged

Add nonstring attribute to fix Clang build errors#282
mutability merged 1 commit intoflightaware:devfrom
zfogg:fix/nonstring-attribute-warnings

Conversation

@zfogg
Copy link
Copy Markdown

@zfogg zfogg commented Jan 14, 2026

Summary

  • Adds __attribute__((nonstring)) to two character arrays that are intentionally sized without room for a null terminator
  • Fixes build failure with modern Clang when -Werror is enabled

Details

The ais_charset (64-char AIS lookup table) and spinner (4-char animation) arrays are used as raw byte lookup tables, not C strings. Clang's -Wunterminated-string-initialization warning (promoted to error by -Werror) causes the build to fail.

The nonstring attribute is the idiomatic fix—it documents intent and is more targeted than disabling the warning globally via compiler flags.

Test plan

  • Verified build succeeds with Clang 21

These character arrays are intentionally sized to exactly fit their
contents without a null terminator - they are used as lookup tables,
not C strings. Modern Clang fails to build with -Werror due to
-Wunterminated-string-initialization.

The nonstring attribute documents the intent and silences the error
without requiring global compiler flag changes.
@mutability mutability changed the base branch from master to dev March 25, 2026 14:47
@mutability mutability merged commit 3fb6048 into flightaware:dev Mar 25, 2026
@mutability
Copy link
Copy Markdown

Thanks, & sorry it took so long to get to this!

@mutability
Copy link
Copy Markdown

mutability commented Mar 26, 2026

This actually fails on clang-20, do you know the minimum clang version to support the attribute?
(Oh, I guess clang-21 based on the original PR description)

https://github.com/flightaware/dump1090/actions/runs/23574105571/job/68642789458

clang-20  -I. -D_POSIX_C_SOURCE=200112L -DMODES_DUMP1090_VERSION=\"unknown\" -DMODES_DUMP1090_VARIANT=\"dump1090-fa\" -D_DEFAULT_SOURCE -DENABLE_CPUFEATURES -Icpu_features/include -DENABLE_RTLSDR -DENABLE_BLADERF -DENABLE_HACKRF -DENABLE_LIMESDR -DENABLE_SOAPYSDR -DSTARCH_MIX_X86 -O3 -g -std=c11 -fno-common -Wall -Wmissing-declarations -Werror -Wformat-signedness -W -I/usr/include/ -I/usr/include/  -I/usr/include/libhackrf -I/usr/include/libusb-1.0  -c interactive.c -o interactive.o
interactive.c:143:37: error: unknown attribute 'nonstring' ignored [-Werror,-Wunknown-attributes]
  143 |     char spinner[4] __attribute__ ((nonstring)) = "|/-\\";
      |                                     ^~~~~~~~~
1 error generated.

(I'll put together some conditional compilation)

mutability added a commit that referenced this pull request Mar 26, 2026
clang-20 complains by default about unrecognized attributes, so only
include nonstring for >= 21

Do the same for gcc <10, since we don't do any testing on those older
versions.

This should fix some clang fallout from merging #282
@mutability
Copy link
Copy Markdown

mutability commented Mar 26, 2026

Could you check that the dev branch including 34ecd43 works okay on clang-21? (I don't have a clang-21 readily accessible)

@zfogg
Copy link
Copy Markdown
Author

zfogg commented Mar 28, 2026

@mutability i checked llvm21/clang21 at commit 34ecd43 and it compiles successfully. i checked clang22 also and it works as well. you're all good now.

@zfogg zfogg deleted the fix/nonstring-attribute-warnings branch March 28, 2026 01:07
@zfogg
Copy link
Copy Markdown
Author

zfogg commented Mar 28, 2026

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants