Commit Graph

91 Commits

Author SHA1 Message Date
Xiang Xiao
b2f3a4b5f9 tools/nxstyle: Support the white list
and add _Exit to the white list

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2020-06-28 21:07:57 +01:00
Xiang Xiao
dde25b0f80 tools/nxstyle: Fix AddressSanitizer error
=================================================================
==2474==ERROR: AddressSanitizer: stack-buffer-underflow on address 0x7fffb7e59b5f at pc 0x561fffec79f6 bp 0x7fffb7e59ac0 sp 0x7fffb7e59ab0
READ of size 1 at 0x7fffb7e59b5f thread T0
    #0 0x561fffec79f5 in block_comment_width /home/xiaoxiang/mirtos/nuttx/tools/nxstyle.c:355

Address 0x7fffb7e59b5f is located in stack of thread T0 at offset 31 in frame
    #0 0x561fffec7b90 in get_line_width /home/xiaoxiang/mirtos/nuttx/tools/nxstyle.c:419

  This frame has 1 object(s):
    [32, 544) 'line' (line 420) <== Memory access at offset 31 underflows this variable
HINT: this may be a false positive if your program uses some custom stack unwind mechanism, swapcontext or vfork
      (longjmp and C++ exceptions *are* supported)
SUMMARY: AddressSanitizer: stack-buffer-underflow /home/xiaoxiang/mirtos/nuttx/tools/nxstyle.c:355 in block_comment_width
Shadow bytes around the buggy address:
  0x100076fc3310: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x100076fc3320: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x100076fc3330: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x100076fc3340: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x100076fc3350: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x100076fc3360: 00 00 00 00 00 00 00 00 f1 f1 f1[f1]00 00 00 00
  0x100076fc3370: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x100076fc3380: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x100076fc3390: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x100076fc33a0: 00 00 00 00 00 00 00 00 00 00 00 00 f3 f3 f3 f3
  0x100076fc33b0: f3 f3 f3 f3 00 00 00 00 00 00 00 00 00 00 00 00
Shadow byte legend (one shadow byte represents 8 application bytes):
  Addressable:           00
  Partially addressable: 01 02 03 04 05 06 07
  Heap left redzone:       fa
  Freed heap region:       fd
  Stack left redzone:      f1
  Stack mid redzone:       f2
  Stack right redzone:     f3
  Stack after return:      f5
  Stack use after scope:   f8
  Global redzone:          f9
  Global init order:       f6
  Poisoned by user:        f7
  Container overflow:      fc
  Array cookie:            ac
  Intra object redzone:    bb
  ASan internal:           fe
  Left alloca redzone:     ca
  Right alloca redzone:    cb
  Shadow gap:              cc
==2474==ABORTING

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
Change-Id: Ie7dee3cdfdbbd04ea9cdb58e227afef07073cecd
2020-06-16 09:56:22 -06:00
Gregory Nutt
3b62765edd nxstyle: Fix distinction be source and header file for long lines.
For some unknow reason, long lines were reported as WARNING is header files, but as ERRORS in C source file.  There are errors where ever they occur.
2020-05-19 20:09:57 -04:00
Nathan Hartman
3334b40aef nxstyle: Allow Hz, KHz, GHz in identifiers
Per the coding standard, we allow MHz as one of the few allowed
exceptions to the identifier case rules.

However, because this exception specifically looked for "MHz" we
would generate undeserved nxstyle errors for Hz, KHz, GHz.

This change adds recognition of any Hz value by eliminating the
requirement for Hz to be preceded by M.

tools/nxstyle.c:

    * main(): Eliminate requirement for Hz to be preceded by M to
      match the rule for allowed mixed case identifier. Update
      relevant comments.

See:
https://cwiki.apache.org/confluence/display/NUTTX/Coding+Standard#macros

Mailing list discussion archived at:
https://lists.apache.org/thread.html/r481b9d145f439c24c8d70992081bf670bc0e893167149e0017519439%40%3Cdev.nuttx.apache.org%3E
2020-05-18 18:00:10 -06:00
Gregory Nutt
58589db931 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
2020-04-06 19:47:57 +01:00
raiden00pl
15242a65b6 tools/nxstyle.c: handle scientific notation with a negative exponent (eg. 9e-10) 2020-04-03 10:47:32 -06:00
Gregory Nutt
65739a38fb tools/nxstyle.c: Alloc MHz in pre-processor variable names.
The sub-string MHz is used frequently is pre-processor variable definitions.  The section "Lowercase Exceptions" permits reasonable use of lowercase characters in pre-processor variable names and, given the frequency of the use of MHz (no pun intended), it certainly should qualify.
2020-04-02 20:29:26 +01:00
Gregory Nutt
a34e5fc043 tools/nxstyle.c: All Public Function Prototypes in C files
Allow "Public Function Prototypes" sections in .c files.  Per the coding standard, all public function prototypes belong in .c files.  However, there are some situations when the public function prototype is needed in a .c file and it shoudld, most correctly, be placed in a "Public Function Prototypes" section.
2020-04-01 22:57:51 +01:00
Gregory Nutt
7f510a61b4 tools/nxstyle.c: Add fixedmath.h defines to white-listed prefixes
Checking for white-listed prefixes is also simpler now because the check is table driver.  New data structure:  g_white_prefix[] and new function white_prefix().
2020-03-31 19:26:26 +01:00
Gregory Nutt
652e152d66 tools/nxstyle: Ignore stub names that begin with STUB_*
The names use for stub functions follows a non-standard convention:  They begin with STUB_
2020-03-21 19:06:32 +01:00
Johannes Schock
898141300c Don't check position of comments right of code when separated by preprocessor line without comment. 2020-03-19 09:36:57 -06:00
Johanne Schock
cdf615855a Added assembly header detection. 2020-03-14 08:38:39 -06:00
Johanne Schock
645cf6d547 Handling of struct initializers changed.
Break conditionals with || at the end.
2020-03-13 07:58:52 -06:00
johannes-nivus
45196cad17
tools/nxstyle.c: Check for missing space before closing comment faulty (#543)
*Addresses Issue #540, check for missing space before closing comment was faulty
2020-03-11 11:08:01 -06:00
liuhaitao
aa4052936c tools/nxstyle: clean up the no and unknown file extension info
Clean up the no and unknown file extension info since only .h and .c
files supported. Just ignore them quietly.

Signed-off-by: liuhaitao <liuhaitao@xiaomi.com>
2020-03-10 08:43:23 -06:00
Johanne Schock
0b4ffa20a8 Checks for multiline comments right of #el..., changes message for a certain case of a comment following a right of code comment 2020-03-10 07:06:35 -06:00
Johanne Schock
f764947c73 Signal error for multiline comment right of #if 2020-03-09 10:00:26 -06:00
Johanne Schock
745e0a4ca9 Some more fine tuning
Handle #define different than other preprocessor lines
Ignore backslash at the end of a comment right of a preprocessor line
2020-03-09 10:00:26 -06:00
Johanne Schock
5e5b6c2069 Finetuning false positive 2020-03-09 10:00:26 -06:00
Johanne Schock
fbe65a2d7d Restrict check of right of code comments to #define in case of preprocessor lines 2020-03-09 10:00:26 -06:00
Johanne Schock
46b8347217 Style 2020-03-09 10:00:26 -06:00
Johanne Schock
b324596bac Formatting 2020-03-09 10:00:26 -06:00
Johanne Schock
574344c56e Changes to nxstyle which address issue #120 and add checks for column position of right of code comments 2020-03-09 10:00:26 -06:00
Johanne Schock
62c2b4aac7 nxstyle fixes
fixed coloumn number of error messages PR #487
fixed lineno_min = lineno_min
2020-03-08 07:29:30 -06:00
Johanne Schock
77d02e98a0 Implemented comment processing for preprocessor lines 2020-03-08 06:36:54 -06:00
David Sidrane
c5b4d9b628 nxstyle:nxstyle should pass nxstyle checks! 2020-03-07 08:31:36 -06:00
David Sidrane
8b1dc2825f Update nxstyle.c 2020-03-06 15:49:59 -06:00
YAMAMOTO Takashi
45a8edd227 nxstyle: Output line numbers when complaining on block comments length 2020-03-06 07:25:52 -06:00
YAMAMOTO Takashi
0715ab3132 Revert "tools/nxstyle: Back out part of last commit. Logic to avoid some false alarms was causing real style problems from being reported."
If we are going to use this tool for things like
git pre-commit hook or CI workflow, it's critical to
avoid false alarms.

This reverts commit de764af9aa.
2020-03-06 07:25:11 -06:00
YAMAMOTO Takashi
4879f2225e nxstyle: Don't complain on ELF things like Elf32_Hdr 2020-03-05 21:18:12 -06:00
YAMAMOTO Takashi
e5ea0ac32d nxstyle: Don't parse a file if its type is unknown 2020-03-05 20:18:11 -06:00
Gregory Nutt
75e3af0985 tools/nxstyle: Allow mixed case system calls.
System calls have mixed case.  They begin with SYS_ but then are followed by the system function name in lower case.
2020-02-14 17:22:18 +01:00
Gregory Nutt
dfcbc42679 tools/nxstyle.c: Fix logic error in previous change. 2020-02-03 22:26:28 +01:00
Gregory Nutt
2483b65bfb tools/nxstyle.c: Ignore inttypes.h constants.
Eliminate warnings.  Ignore mixed case identifies beginning with PRIx.
These most likely come from inttypes.h and we nxstyle must tolerate
those definitions even though they do not follow the coding style.
2020-02-03 17:51:09 +01:00
Gregory Nutt
94483cf400 tools/nxstyle.c: Add logic to detect check for left brace in first column, but preceded by a blank line. That should never happen for the outermost opening branch (but could happen with internal compound statements).
Consider junk.c for example:

    /****************************************************************************
     * xx
     ****************************************************************************/

    /****************************************************************************
     * Private Types
     ****************************************************************************/

    struct foo_s

    {
      int bar;
    };

    /****************************************************************************
     * Public Functions
     ****************************************************************************/

    int dofoo(int barin)

    {
      barout = barin;
      return barout;
    }

nxstyle not detects these problems:

    $ tools/nxstyle.exe junk.c
    junk.c:11:0: error: Blank line before opening left brace
    junk.c:21:0: error: Blank line before opening left brace
2020-01-28 12:26:01 -03:00
patacongo
0e77e3373e tools/nxstyle.c: Correct false alarm detection (#106)
Commit cf5d17f795 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.
2020-01-15 20:22:37 +00:00
Gregory Nutt
cf5d17f795 tools/nxstyle: Added logic to parse section headers (#90)
* tools/nxstyle:  Added logic to parse section headers (like Included files, Pre-processor Definitions, etc.) and to assure that the section headers are correct for the file type.  Also (1) verify that #include appears only in the 'Included Files' section and that (2) #define only occurs in the Pre-processor definition section.

    Right now, there are several places where that rule is not followed.  I think most of these are acceptable so these failures only generate warnings, not errors.  The warning means that we need to go look at the offending #define or #include and decide if it is a acceptable usage or not.
2020-01-13 18:08:45 +00:00
Gregory Nutt
beae24c8c0 tools/nxstyle.c: Correct indexing error noted by Xaio Xaing in commit comments. 2020-01-12 14:52:48 -03:00
Gregory Nutt
6309165fe0 tools/nxstyle.c: Add automatic detection of line width based on examining
the width of all block comments. Includes a check to assure that all block
comments use the same line width.

Verified against all .c files under /sched.  There were a few cosmetic changes to the coding style under /sched to account to new, correctly detected problems in the /sched files.
2020-01-12 13:07:54 -03:00
liuguo09
1c53d2b616 Nxstyle checkpatch support (#47)
* tools/nxstyle.c: Donot check unknown file extension files

nxstyle only support c soure file and header file check, donot check
other unknown file extension files.

* tools/checkpatch.sh: Add checkpatch.sh script based on nxstyle tool

Usage:
checkpatch.sh patch-list // default as patch list
checkpatch.sh -p patch-list
checkpatch.sh -c commit-list
checkpatch.sh -f file-list
checkpatch.sh - // read from stdin, which used by git pre-commit hook

And git pre-commit hook could use checkpatch.sh as below:
git diff --cached | ./tools/checkpatch.sh -
2020-01-07 08:14:01 -06:00
liuhaitao
7da409f3b5 tools/nxstyle.c: Add -r option to check specified range lines
Usage: ./nxstyle -r start,count filename

nxstyle with -r option used to parse the range lines rather than the whole file.

Change-Id: I58ec56511fde14d6ec914400a7849e69960a3711
Signed-off-by: liuhaitao <liuhaitao@xiaomi.com>
2020-01-04 07:58:00 -06:00
David Sidrane
002772c81e nxstyle improvements with No tooling (#12)
tools/nxstyle.c:  Output compiler like error format.  Added features

   Uses getops to pars command line.
   Supports
      -s silence all output
      -g provide a PASS fail message

* tools/README.txt:  Update with new nxstyle options
2019-12-30 21:01:41 -06:00
Gregory Nutt
504b0e8b5b drivers/wireless: Run all wireless drivers through tools/nxstyle, correcting as many complaints as possible. 2019-12-05 11:49:12 -06:00
Gregory Nutt
d87295f328 tools/Directories.mk, Makefile.*: Extend the clean_context target so that it will remove the autogenerated files created during the context phase of the initial build. 2019-12-03 06:38:53 -06:00
Gregory Nutt
d2af57169b tools/nxstyle.c: Fix a rare false alarm that could occur if a variable or function name begins with the sub-string 'union' or 'struct'. misc fixes under fs/ and sched/ from application of current version of nxstyle. 2019-12-01 13:01:16 -06:00
Gregory Nutt
91d04837e9 tools/nxstyle.c: Eliminate some false alarms related to comments to the right of code about alignment and spacing. 2019-12-01 11:37:30 -06:00
Gregory Nutt
8bc55d4396 tools/nxstyle.c: Trivial improvement to preceding change to allow white space separation. 2019-11-19 11:43:20 -06:00
Gregory Nutt
f3c2022b4e tools/nxstyle: Fix false alarm 'Garbage follows right bracket' on named structures that are fields of other structures or unions. 2019-11-19 11:32:57 -06:00
Gregory Nutt
a9ef2b4208 tools/nxstyle.c: Eliminate false positive 'Invalid character after asterisk in comment block'. 2019-11-09 12:10:43 -06:00
Matias Nitsche
e118d99bf5 drivers/power/pm: Historically, the NuttX PM subsystem has consisted of two functional components: (1) an "Upper" part that detects state changes based on a random walk driven by activity levels, and (2) and "lower" part that implementst the state changes.
This change decouples that upper activity-based logic from the lower random walk logic and allows use of other upper state detection logic (such as a custom, application-specific state machine).
2019-11-09 09:09:33 -06:00