[clang] [clang][Analyzer] Move checker 'alpha.unix.Errno' to 'unix.Errno'. (PR #69469)

via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 26 05:45:28 PDT 2023


DonatNagyE wrote:

I also think that the [reports](https://codechecker-demo.eastus.cloudapp.azure.com/Default/report-detail?run=postgres_REL_13_0_errno_alpha_unix&newcheck=postgres_REL_13_0_errno_unix&is-unique=on&diff-type=New&report-id=3253666&report-hash=b4e0b723164236269fe6078ad32a0456&report-filepath=%2apg_basebackup.c) [from](https://codechecker-demo.eastus.cloudapp.azure.com/Default/report-detail?run=postgres_REL_13_0_errno_alpha_unix&newcheck=postgres_REL_13_0_errno_unix&is-unique=on&diff-type=New&report-id=3254052&report-hash=619eb5d998324adb5e02d9e3302bb4d5&report-filepath=%2acopy.c) [postgres](https://codechecker-demo.eastus.cloudapp.azure.com/Default/report-detail?run=postgres_REL_13_0_errno_alpha_unix&newcheck=postgres_REL_13_0_errno_unix&is-unique=on&diff-type=New&report-id=3256373&report-hash=32f8e213c6fb419277ec76c40bfa3956&report-filepath=%2afe-connect.c) that you mentioned are too confusing. They follow this pattern:

![image](https://github.com/llvm/llvm-project/assets/43410265/4a019304-01a6-400c-8a00-4a147e2f1951)

The function `fwrite()` is declared as
```c
size_t fwrite(const void *restrict ptr, size_t size, size_t nitems,
           FILE *restrict stream);
```
and it usually indicates success by returning the value of `nitems` -- but it has a corner case that if `size` is 0, then it does nothing and returns 0. This corner case is considered to be a successful call, and the bug reports are generated when the analyzer follows this case and notices that `errno` contains an undefined value.

I think that in these reports it would be important to replace the generic "`after successful call to 'fwrite'`" with a concrete message which highlight that the analyzer is following this obscure corner case (which is sometimes missing from the documentation, for example on my system `man 3 fwrite` from release 5.05 of the Linux man-pages project does not mention it).


https://github.com/llvm/llvm-project/pull/69469


More information about the cfe-commits mailing list