| 191 | //--------------------------------------------------------------------------- |
| 192 | |
| 193 | static bool getDimensionsEtc(const Token * const arrayToken, const Settings &settings, std::vector<Dimension> &dimensions, ErrorPath &errorPath, bool &mightBeLarger, MathLib::bigint &path) |
| 194 | { |
| 195 | const Token *array = arrayToken; |
| 196 | while (Token::Match(array, ".|::")) |
| 197 | array = array->astOperand2(); |
| 198 | |
| 199 | if (array->variable() && array->variable()->isArray() && !array->variable()->dimensions().empty()) { |
| 200 | dimensions = array->variable()->dimensions(); |
| 201 | if (dimensions[0].num <= 1 || !dimensions[0].tok) { |
| 202 | visitAstNodes(arrayToken, |
| 203 | [&](const Token *child) { |
| 204 | if (child->originalName() == "->") { |
| 205 | mightBeLarger = true; |
| 206 | return ChildrenToVisit::none; |
| 207 | } |
| 208 | return ChildrenToVisit::op1_and_op2; |
| 209 | }); |
| 210 | } |
| 211 | } else if (const Token *stringLiteral = array->getValueTokenMinStrSize(settings, &path)) { |
| 212 | Dimension dim; |
| 213 | dim.tok = nullptr; |
| 214 | dim.num = Token::getStrArraySize(stringLiteral); |
| 215 | dim.known = array->hasKnownValue(); |
| 216 | dimensions.emplace_back(dim); |
| 217 | } else if (array->valueType() && array->valueType()->pointer >= 1 && (array->valueType()->isIntegral() || array->valueType()->isFloat())) { |
| 218 | const ValueFlow::Value *value = getBufferSizeValue(array); |
| 219 | if (!value) |
| 220 | return false; |
| 221 | path = value->path; |
| 222 | errorPath = value->errorPath; |
| 223 | Dimension dim; |
| 224 | dim.known = value->isKnown(); |
| 225 | dim.tok = nullptr; |
| 226 | const auto sizeOf = array->valueType()->pointer > 1 ? ValueType::SizeOf::Pointer : ValueType::SizeOf::Pointee; |
| 227 | const size_t typeSize = array->valueType()->getSizeOf(settings, ValueType::Accuracy::ExactOrZero, sizeOf); |
| 228 | if (typeSize == 0) |
| 229 | return false; |
| 230 | dim.num = value->intvalue / typeSize; |
| 231 | dimensions.emplace_back(dim); |
| 232 | } |
| 233 | return !dimensions.empty(); |
| 234 | } |
| 235 | |
| 236 | static ValueFlow::Value makeSizeValue(MathLib::bigint size, MathLib::bigint path) |
| 237 | { |
no test coverage detected