negative_error_code: add special handling for negative checks
commit5e0a89bf072d343b9949773254f4f1032c56dbf1
authorDan Carpenter <dan.carpenter@linaro.org>
Mon, 24 Jul 2023 13:40:00 +0000 (24 16:40 +0300)
committerDan Carpenter <dan.carpenter@linaro.org>
Mon, 24 Jul 2023 13:40:00 +0000 (24 16:40 +0300)
tree320b787aa51fb15d8335d18ea972a15bf8b4c517
parent17d82eca8fc6b4d100fb8d7eba476e477574441d
negative_error_code: add special handling for negative checks

This code was already using the information from Smatch extra to say that
positive values were not error codes.  The issue is that you sometimes
have code like:

int bytes;
long ret = some_function();

if (ret < 0)
return ret;

bytes = ret;

The problem is that bytes is int and ret is long.  So smatch thinks that
at the end, if there is a high value of ret it could be truncated into a
negative value in bytes.  This isn't going to happen, but that's how Smatch
thinks.

So just make it explicit that if there is a < 0 check the positive values
are not error codes.

Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
check_returns_negative_error_code.c