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

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

Closed
jphickey opened this issue Sep 16, 2019 · 1 comment
Closed
Labels
unit-test Tickets related to the OSAL unit testing (functional and/or coverage)
Milestone

Comments

@jphickey
Copy link
Contributor

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.

@jphickey jphickey changed the title String Literals not correctly qualified as "const" in some unit tests Many compiler warnings in unit tests when using strict compiler flags Sep 16, 2019
@jphickey
Copy link
Contributor Author

Other warnings observed: "function declaration isn’t a prototype" in ut_oscore_test.c, and unused variable in ut_osfile_dirio_test.c.

Should fix all of them.

jphickey added a commit to jphickey/osal that referenced this issue Sep 16, 2019
Qualify all pointers referring to string literals as `const`
Eliminate unused local variables
Add missing local function prototypes.
@skliper skliper added this to the 5.0.0 milestone Sep 19, 2019
skliper added a commit that referenced this issue Oct 1, 2019
skliper added a commit that referenced this issue Oct 1, 2019
Reviewed and approved at 2019-09-25 CCB
skliper pushed a commit that referenced this issue Oct 1, 2019
Qualify all pointers referring to string literals as `const`
Eliminate unused local variables
Add missing local function prototypes.
skliper added a commit that referenced this issue Oct 1, 2019
Reviewed and approved at 2019-09-25 CCB
@skliper skliper closed this as completed in ba82d52 Oct 2, 2019
@astrogeco astrogeco added the unit-test Tickets related to the OSAL unit testing (functional and/or coverage) label Sep 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
unit-test Tickets related to the OSAL unit testing (functional and/or coverage)
Projects
None yet
Development

No branches or pull requests

3 participants