From: Roland Dobai Date: Fri, 6 Apr 2018 14:04:13 +0000 (+0200) Subject: Enable -Wwrite-strings when compiling IDF's own C files X-Git-Tag: v3.1-beta1~273^2~1 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=33480d1a2c284afccfe14cbcef94d8a30eefa2fd;p=esp-idf Enable -Wwrite-strings when compiling IDF's own C files --- diff --git a/Kconfig b/Kconfig index 7cf6901029..6dfaa31838 100644 --- a/Kconfig +++ b/Kconfig @@ -148,6 +148,20 @@ config STACK_CHECK help Stack smashing protection. +config WARN_WRITE_STRINGS + bool "Enable -Wwrite-strings warning flag" + default "n" + help + Adds -Wwrite-strings flag for the C/C++ compilers. + + For C, this gives string constants the type "const char[]" so that + copying the address of one into a non-"const" "char *" pointer + produces a warning. This warning helps to find at compile time code + that tries to write into a string constant. + + For C++, this warns about the deprecated conversion from string + literals to "char *". + endmenu # Compiler Options menu "Component config" diff --git a/make/project.mk b/make/project.mk index 8640319cfe..36cfce7205 100644 --- a/make/project.mk +++ b/make/project.mk @@ -267,6 +267,10 @@ COMMON_WARNING_FLAGS = -Wall -Werror=all \ -Wextra \ -Wno-unused-parameter -Wno-sign-compare +ifdef CONFIG_WARN_WRITE_STRINGS +COMMON_WARNING_FLAGS += -Wwrite-strings +endif #CONFIG_WARN_WRITE_STRINGS + # Flags which control code generation and dependency generation, both for C and C++ COMMON_FLAGS = \ -ffunction-sections -fdata-sections \ diff --git a/tools/unit-test-app/sdkconfig.defaults b/tools/unit-test-app/sdkconfig.defaults index a9a34a25a8..e2ca5f4339 100644 --- a/tools/unit-test-app/sdkconfig.defaults +++ b/tools/unit-test-app/sdkconfig.defaults @@ -26,3 +26,4 @@ CONFIG_STACK_CHECK=y CONFIG_SUPPORT_STATIC_ALLOCATION=y CONFIG_ESP_TIMER_PROFILING=y CONFIG_ADC2_DISABLE_DAC=n +CONFIG_WARN_WRITE_STRINGS=y