]> granicus.if.org Git - esp-idf/commitdiff
Enable -Wwrite-strings when compiling IDF's own C files
authorRoland Dobai <dobai.roland@gmail.com>
Fri, 6 Apr 2018 14:04:13 +0000 (16:04 +0200)
committerRoland Dobai <dobai.roland@gmail.com>
Tue, 10 Apr 2018 06:53:33 +0000 (08:53 +0200)
Kconfig
make/project.mk
tools/unit-test-app/sdkconfig.defaults

diff --git a/Kconfig b/Kconfig
index 7cf6901029f8692eaced366b2cb07a994bfc4ab9..6dfaa31838d473acf1a0a64c50466a05ac69685f 100644 (file)
--- 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"
index 8640319cfe36968daddb74f19adf8b7cb78e328c..36cfce7205617083646c3e1e2b8a21f7e71932c3 100644 (file)
@@ -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 \
index a9a34a25a8fd9c28e34ba5454b2e29d3e8370c7d..e2ca5f4339faf2a969e38fec63cb146b51fcdcc1 100644 (file)
@@ -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