| 970 | } |
| 971 | |
| 972 | static void valueFlowRightShift(TokenList& tokenList, const Settings& settings) |
| 973 | { |
| 974 | for (Token* tok = tokenList.front(); tok; tok = tok->next()) { |
| 975 | if (tok->str() != ">>") |
| 976 | continue; |
| 977 | |
| 978 | if (tok->hasKnownIntValue()) |
| 979 | continue; |
| 980 | |
| 981 | if (!tok->astOperand1() || !tok->astOperand2()) |
| 982 | continue; |
| 983 | |
| 984 | if (!tok->astOperand2()->hasKnownIntValue()) |
| 985 | continue; |
| 986 | |
| 987 | const MathLib::bigint rhsvalue = tok->astOperand2()->getKnownIntValue(); |
| 988 | if (rhsvalue < 0) |
| 989 | continue; |
| 990 | |
| 991 | if (!tok->astOperand1()->valueType() || !tok->astOperand1()->valueType()->isIntegral()) |
| 992 | continue; |
| 993 | |
| 994 | if (!tok->astOperand2()->valueType() || !tok->astOperand2()->valueType()->isIntegral()) |
| 995 | continue; |
| 996 | |
| 997 | MathLib::bigint lhsmax = 0; |
| 998 | if (!getExpressionRange(tok->astOperand1(), nullptr, &lhsmax)) |
| 999 | continue; |
| 1000 | if (lhsmax < 0) |
| 1001 | continue; |
| 1002 | std::uint8_t lhsbits; |
| 1003 | if ((tok->astOperand1()->valueType()->type == ValueType::Type::CHAR) || |
| 1004 | (tok->astOperand1()->valueType()->type == ValueType::Type::SHORT) || |
| 1005 | (tok->astOperand1()->valueType()->type == ValueType::Type::WCHAR_T) || |
| 1006 | (tok->astOperand1()->valueType()->type == ValueType::Type::BOOL) || |
| 1007 | (tok->astOperand1()->valueType()->type == ValueType::Type::INT)) |
| 1008 | lhsbits = settings.platform.int_bit; // TODO: needs to use the proper *_bit fo each type |
| 1009 | else if (tok->astOperand1()->valueType()->type == ValueType::Type::LONG) |
| 1010 | lhsbits = settings.platform.long_bit; |
| 1011 | else if (tok->astOperand1()->valueType()->type == ValueType::Type::LONGLONG) |
| 1012 | lhsbits = settings.platform.long_long_bit; |
| 1013 | else |
| 1014 | continue; |
| 1015 | if (rhsvalue >= lhsbits || rhsvalue >= MathLib::bigint_bits || (1ULL << rhsvalue) <= lhsmax) |
| 1016 | continue; |
| 1017 | |
| 1018 | ValueFlow::Value val(0); |
| 1019 | val.setKnown(); |
| 1020 | setTokenValue(tok, std::move(val), settings); |
| 1021 | } |
| 1022 | } |
| 1023 | |
| 1024 | static std::vector<MathLib::bigint> minUnsignedValue(const Token* tok, int depth = 8) |
| 1025 | { |
no test coverage detected