pangzhen1xiaomi opened a new pull request, #22079:
URL: https://github.com/apache/nuttx/pull/22079
## Summary
Coverity / MISRA C fixes in the stdio stream flags and sched/tls. The
code generated by these functions is unchanged in behaviour; the changes
only make types and control flow explicit for static analysis:
* **stdio: make __FS_FLAG_* stream flag macros unsigned**
`fs_flags` in `struct file_struct` is unsigned, so define the flag
macros as `(1u << n)` (MISRA C-2012 Rule 10.4).
* **sched/tls: avoid converting uintptr_t to void * directly**
Initialize the stdio stream cookie through `(FAR char *)(intptr_t)i`
instead of converting directly to `void *`.
* **sched/tls: cast values assigned to narrower uint16_t fields**
`fs_oflags` and `tl_size` are `uint16_t`; cast the `int` open flags and
the `ptrdiff_t` stack size explicitly (MISRA C-2012 Rule 10.3).
* **sched/tls: functions should have exactly one exit point**
Replace the early `return -ENOMEM` in `task_init_info()`,
`tls_dup_info()` and `tls_init_info()` with a single `return ret`
(MISRA C-2004 Rule 14.7).
These come from running Coverity with MISRA rules on NuttX for a
functional safety project, the same kind of change as the earlier
sched/irq series (e.g. #18175).
## Impact
* Is new feature added? Is existing feature changed? NO.
* Impact on user (will user need to adapt to change)? NO.
* Impact on build (will build process change)? NO.
* Impact on hardware (will arch(s) / board(s) / driver(s) change)? NO.
* Impact on documentation (is update required / provided)? NO.
* Impact on security (any sort of implications)? NO.
* Impact on compatibility (backward/forward/interoperability)? NO. The
`__FS_FLAG_*` values are unchanged; only their type becomes unsigned.
* Anything else to consider or add? NO.
## Testing
I confirm that changes are verified on local setup and works as intended:
* Build Host(s): Ubuntu 22.04.5 LTS, x86_64, gcc 13.4.0,
arm-none-eabi-gcc 13.2.1
* Target(s): sim:nsh, sim:smp, lm3s6965-ek:qemu-kostest (QEMU). Not
tested on real hardware.
* `./tools/checkpatch.sh -m -g` on all four commits: pass.
* sim:nsh and sim:smp (make, `CONFIG_FILE_STREAM=y`, `CONFIG_TLS_EMUTLS=y`):
build OK, no new warnings, `ostest` exits with status 0 on both.
* sim:nsh CMake build: OK.
* Each commit builds on its own (sim:nsh).
* `lm3s6965-ek:qemu-kostest` (PROTECTED build, `CONFIG_MM_KERNEL_HEAP=y`,
which compiles the `group_zalloc()` path of `task_init_info()`): builds
with no warnings. Under QEMU, master and this PR stop at the same
existing assertion before ostest starts (`init/nx_bringup.c:458`,
`DEBUGASSERT(pid > 0)` after creating AppBringUp); boot output is
identical before and after the change.
Testing logs before change (master, sim:nsh ostest):
```
user_main: Exiting
ostest_main: Exiting with status 0
nsh> poweroff
```
Testing logs after change (sim:nsh and sim:smp ostest):
```
user_main: Exiting
ostest_main: Exiting with status 0
nsh> poweroff
```
## PR verification Self-Check
* [x] This PR introduces only one functional change.
* [x] I have updated all required description fields above.
* [x] My PR adheres to Contributing Guidelines and Documentation (git commit
title and message, coding standard, etc).
* [ ] My PR is still work in progress (not ready for review).
* [x] My PR is ready for review and can be safely merged into a codebase.
--
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]