-
Notifications
You must be signed in to change notification settings - Fork 245
Description
Describe the bug
For historical backward-compatibility reasons ANSI C defines string literals as char* type, but these strings are typically put into an .rodata section on modern processors/linkers, and this section is usually write-protected. If code actually attempts to modify this value, it will generate a segmentation fault and crash.
Building with -Wwrite-strings causes the compiler to treat string literals as const char * instead, thereby generating a warning if passed or assigned to a non-const pointer value.
To Reproduce
Configure with make OSAL_USER_C_FLAGS='-Wall -Werror -std=c99 -pedantic -Wwrite-strings' ENABLE_UNIT_TESTS=true and observe many warnings generated in the unit test code.
Expected behavior
The build should be free of warnings, such that -Wwrite-strings can be enabled by default.
System observed on:
Ubuntu 18.04 (64-bit)
Reporter Info
Joseph Hickey, Vantage Systems, Inc.