This is an automated email from the ASF dual-hosted git repository.

aguettouche pushed a commit to branch pr106
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git


The following commit(s) were added to refs/heads/pr106 by this push:
     new 247c8ee  tools/nxstyle.c:  Correct false alarm detection (#106)
247c8ee is described below

commit 247c8eec15cb2bf54bdee6f40c29bdafda3c1f26
Author: patacongo <spudar...@yahoo.com>
AuthorDate: Wed Jan 15 13:25:18 2020 -0600

    tools/nxstyle.c:  Correct false alarm detection (#106)
    
    Commit cf5d17f7959a593b87b7d624a8ac63f241f8cd85 added logic to detect 
#define pre-processor definitions outside of the "Pre-processor Definitions" 
file section.  That commit was verified against numerous .c source files.  But 
not against any .h header files.
    
    When run against a header file, that change causes a false alarm warning 
like:
    
      file:line:pos: warning: #define outside of 'Pre-processor Definitions' 
section
    
    That is caused the idempotence, guard definition that must appear in the 
header file BEFORE the first file section.
    
    This commit adds logic to nxstyle to ignore pre-processor definitions in 
header files that occur before the first file section is encountered.
---
 tools/nxstyle.c | 23 ++++++++++++++++-------
 1 file changed, 16 insertions(+), 7 deletions(-)

diff --git a/tools/nxstyle.c b/tools/nxstyle.c
index edffe12..9592382 100644
--- a/tools/nxstyle.c
+++ b/tools/nxstyle.c
@@ -844,15 +844,24 @@ int main(int argc, char **argv, char **envp)
                      {
                        if (g_section != PRE_PROCESSOR_DEFINITIONS)
                          {
-                           /* Only a warning because there is some usage of
-                            * define outside the Pre-processor Definitions
-                            * section which is justifiable.  Should be
-                            * manually checked.
+                           /* A complication is the header files always have
+                            * the idempotence guard definitions before the
+                            * "Pre-processor Definitions section".
                             */
 
-                           WARN("#define outside of 'Pre-processor "
-                                "Definitions' section",
-                                lineno, ii);
+                           if (g_section == NO_SECTION &&
+                               g_file_type != C_HEADER)
+                             {
+                               /* Only a warning because there is some usage
+                                * of define outside the Pre-processor
+                                * Definitions section which is justifiable.
+                                * Should be manually checked.
+                                */
+
+                               WARN("#define outside of 'Pre-processor "
+                                    "Definitions' section",
+                                    lineno, ii);
+                             }
                          }
                      }
 

Reply via email to