Skip to content

Many compiler warnings in unit tests when using strict compiler flags #15

@jphickey

Description

@jphickey

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    unit-testTickets related to the OSAL unit testing (functional and/or coverage)

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions