casaroli opened a new pull request, #21097:
URL: https://github.com/apache/nuttx/pull/21097

   ## Summary
   
   Two problems in `fnmatch()` (`libs/libc/misc/lib_fnmatch.c`):
   
   - A set without ranges skipped every second character: `[xyz]` did not match 
`y`, and `[a-cxyz]` did not match `y`. The loop read one character as a 
possible start of a range and then stepped over the next one. A `-` before the 
closing `]` (`[a-]`) was taken as a range to `]`. The first commit reads the 
set one item at a time: a character, or a range when a `-` and one more 
character other than `]` follow. A set without the closing `]` no longer 
matches.
   - Programs use two flags that POSIX does not have but other C libraries do: 
`FNM_CASEFOLD` ignores the case, and `FNM_LEADING_DIR` lets the pattern match 
the string up to a `/`. `<fnmatch.h>` did not define them, so these programs 
did not compile. The second commit defines them with the values of the other C 
libraries (16 and 8) and the aliases `FNM_IGNORECASE` and `FNM_FILE_NAME`, and 
implements them, also in sets and ranges.
   
   The third commit adds `Documentation/os/libs/libc/fnmatch.rst`: the pattern 
syntax that this small matcher supports, the two flags, and the flags that have 
no effect.
   
   ## Impact
   
   - `fnmatch()` results change for patterns with sets: `[xyz]` matches `y` 
(was no match), `[a-]` matches `-`, and a set without `]` does not match. 
Patterns without sets do not change. `glob()` uses `fnmatch()`, so a glob 
pattern such as `*.[ch]` now also matches `x.h`. The procfs patterns (`[0-9]*`, 
one range) give the same results.
   - New flags and macros in `<fnmatch.h>`; without them nothing else changes.
   
   All build modes.
   
   ## Testing
   
   Tested on master aeab6fbf989 and on this PR rebased on it.
   
   Test programs on `qemu-armv8a:knsh` (QEMU with HVF):
   
   | Test | master | this PR |
   |---|---|---|
   | `fnmset.c`: 9 set cases without flags | 3 of 9 FAIL: `[xyz]`/`y`, 
`[a-cxyz]`/`y`, `[a-]`/`-` | 9 of 9 PASS |
   | `fnmtest.c`: the 9 set cases + 26 cases with `FNM_CASEFOLD`, 
`FNM_LEADING_DIR` and their combinations with `FNM_PATHNAME`/`FNM_PERIOD` | 
does not compile (flags not defined) | 35 of 35 PASS |
   | ostest, `qemu-armv8a:knsh` and `qemu-armv8a:nsh` | status 0 | status 0 |
   
   Build, each OK: `qemu-armv8a:nsh` (flat, arm64), `qemu-armv8a:knsh` (kernel, 
arm64), `lm3s6965-ek:qemu-protected` (protected, armv7-m), `rv-virt:nsh64` 
(flat, rv64), `rv-virt:pnsh64` (protected, rv64), `rv-virt:knsh64` (kernel, 
rv64).
   
   `tools/checkpatch.sh -c -u -m -g` passes.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to