[PATCH] D63623: [clang-tidy] Add a check on expected return values of posix functions (except posix_openpt) in Android module.
Jian Cai via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Jun 25 23:47:38 PDT 2019
jcai19 marked an inline comment as done.
jcai19 added inline comments.
================
Comment at: clang-tools-extra/clang-tidy/android/PosixReturnCheck.cpp:39
+ const auto &BinOp = *Result.Nodes.getNodeAs<BinaryOperator>("binop");
+ diag(BinOp.getOperatorLoc(), "posix functions (except posix_openpt) never return negative values");
+}
----------------
jcai19 wrote:
> george.burgess.iv wrote:
> > would it be helpful to add fixits for simple cases? e.g. we can probably offer to replace `posix_whatever() < 0` with `posix_whatever() > 0` or `!= 0`
> While this fix is handy, I am not sure whether it will be safe enough under all circumstances. For example, is it possible in the code block following the check, the program calls another POSIX function and alter the errno before its value it checked? In that case, maybe the proper fix should be something as follows and fixing it by changing the binary operator may obscure it:
>
> int ret = posix_whatever();
> if (ret != 0)
After some offline discussion, I agree fixing the simple cases should be fine as programers should verify if the fixes proposed by clang-tidy are correct.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D63623/new/
https://reviews.llvm.org/D63623
More information about the cfe-commits
mailing list