You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by ag...@apache.org on 2020/04/06 18:48:07 UTC

[incubator-nuttx] branch master updated: tools/nxstyle.c: Fix detection of long single line comments.

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

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


The following commit(s) were added to refs/heads/master by this push:
     new 58589db  tools/nxstyle.c:  Fix detection of long single line comments.
58589db is described below

commit 58589db931c3f35d862daee0b544c299f6679eb7
Author: Gregory Nutt <gn...@nuttx.org>
AuthorDate: Mon Apr 6 12:02:29 2020 -0600

    tools/nxstyle.c:  Fix detection of long single line comments.
    
    This resolves issue 718:  nxstyle line width check was ignoring the line width check for single line comments.
    
    This turned out to be an artifact in parsing.  Usually when parsing character by character, the file character to be parsed was '/n'.  Howefver, in the case of parsing single line comments, the final character was the NUL terminator.  This means that the lenth check was not being performed in the case of single line comments.
    
    NOTE:  Currently, I have suppressed error reports for single line right-hand comments.  My fear is that this will unmask more standard violations than we can cope with.  It is easy to re-enable and perhaps we should do that in the future:
    
              /* Check for long lines
               *
               * REVISIT:  Long line checks suppressed on right hand comments
               * for now.  This just prevents a large number of difficult-to-
               * fix complaints that we would have otherwise.
               */
    
              if (m > g_maxline && !rhcomment)  <-- remote the second condition
---
 tools/nxstyle.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++++--------
 1 file changed, 56 insertions(+), 9 deletions(-)

diff --git a/tools/nxstyle.c b/tools/nxstyle.c
index 3da8b6c..e5d9067 100644
--- a/tools/nxstyle.c
+++ b/tools/nxstyle.c
@@ -1721,7 +1721,9 @@ int main(int argc, char **argv, char **envp)
                   {
                     if (n > indent)
                       {
-                        /* REVISIT: dnest is always > 0 here if bfunctions == false */
+                        /* REVISIT: dnest is always > 0 here if bfunctions ==
+                         * false.
+                         */
 
                         if (dnest == 0 || !bfunctions || lineno == rbrace_lineno)
                           {
@@ -1888,7 +1890,9 @@ int main(int argc, char **argv, char **envp)
                           }
                       }
 
-                    /* The right brace should not be preceded with a a blank line */
+                    /* The right brace should not be preceded with a a blank
+                     * line.
+                     */
 
                     if (lineno == blank_lineno + 1)
                       {
@@ -2367,29 +2371,72 @@ int main(int argc, char **argv, char **envp)
 
       /* Loop terminates when NUL or newline character found */
 
-      if (line[n] == '\n')
+      if (line[n] == '\n' || line[n] == '\0')
         {
+          /* If the parse terminated on the NULL, then back up to the last
+           * character (which should be the newline).
+           */
+
+          int m = n;
+          if (line[m] == '\0' && m > 0)
+            {
+              m--;
+            }
+
           /* Check for space at the end of the line.  Except for carriage
            * returns which we have already reported (one time) above.
            */
 
-          if (n > 1 && isspace((int)line[n - 1]) && line[n - 1] != '\r')
+          if (m > 1 && isspace((int)line[m - 1]) &&
+              line[m - 1] != '\n' && line[m - 1] != '\r')
             {
-               ERROR("Dangling whitespace at the end of line", lineno, n);
+               ERROR("Dangling whitespace at the end of line", lineno, m);
             }
 
-          /* Check for long lines */
+          /* The line width is determined by the location of the final
+           * asterisk in block comments.  The closing line of the block
+           * comment will exceed that by one one character, the '/'
+           * following the final asterisk.
+           */
+
+          else if (m > g_maxline)
+            {
+              bool bslash;
+              int a;
+
+              for (bslash = false, a = m;
+                   a > 2 && strchr("\n\r/", line[a]) != NULL;
+                   a--)
+                {
+                  if (line[a] == '/')
+                    {
+                      bslash = true;
+                    }
+                }
+
+              if (bslash && line[a] == '*')
+                {
+                  m = a + 1;
+                }
+            }
+
+          /* Check for long lines
+           *
+           * REVISIT:  Long line checks suppressed on right hand comments
+           * for now.  This just prevents a large number of difficult-to-
+           * fix complaints that we would have otherwise.
+           */
 
-          if (n > g_maxline)
+          if (m > g_maxline && !rhcomment)
             {
               if (g_file_type == C_SOURCE)
                 {
-                  ERROR("Long line found", lineno, n);
+                  ERROR("Long line found", lineno, m);
                 }
               else if (g_file_type == C_HEADER)
 
                 {
-                  WARN("Long line found", lineno, n);
+                  WARN("Long line found", lineno, m);
                 }
             }
         }