| 432 | } |
| 433 | |
| 434 | int vtkXArrayAccessor::get_vars(int vtkNotUsed(ncid), int varid, const size_t* startp, |
| 435 | const size_t* countp, const ptrdiff_t* vtkNotUsed(stridep), int vt, vtkIdType numberOfComponents, |
| 436 | vtkIdType numberOfTuples, vtkDataArray* dataArray) |
| 437 | { |
| 438 | if (static_cast<size_t>(varid) >= this->Var.size()) |
| 439 | return NC_ENOTVAR; |
| 440 | size_t ndims = this->VarDims[varid].size(); |
| 441 | if (std::any_of(countp, countp + ndims, [](size_t val) { return val == 0; })) |
| 442 | { |
| 443 | vtkErrorMacro("Invalid countp: one of the elements is 0"); |
| 444 | return NC_ERANGE; |
| 445 | } |
| 446 | char* arrayStart; |
| 447 | vtkIdType arraySize; |
| 448 | int vtkType = NetCDFTypeToVTKType(this->VarType[varid]); |
| 449 | if (vtkType != vt) |
| 450 | { |
| 451 | vtkErrorMacro("Mismatched VTKType: " << vtkType << ", " << vt); |
| 452 | return NC_ERANGE; |
| 453 | } |
| 454 | |
| 455 | dataArray->SetNumberOfComponents(numberOfComponents); |
| 456 | assert(dataArray->HasStandardMemoryLayout() && "Array must have standard memory layout"); |
| 457 | if (this->IsContiguous(varid, startp, countp)) |
| 458 | { |
| 459 | this->GetContiguousStartSize(varid, startp, countp, arrayStart, arraySize); |
| 460 | if (arraySize != numberOfComponents * numberOfTuples) |
| 461 | { |
| 462 | vtkErrorMacro( |
| 463 | "Mismatch array size: " << arraySize << ", " << (numberOfComponents * numberOfTuples)); |
| 464 | return NC_ERANGE; |
| 465 | } |
| 466 | dataArray->SetVoidArray(arrayStart, arraySize, 1); |
| 467 | } |
| 468 | else |
| 469 | { |
| 470 | dataArray->SetNumberOfTuples(numberOfTuples); // NOLINTNEXTLINE(bugprone-unsafe-functions) |
| 471 | char* dst = static_cast<char*>(dataArray->GetVoidPointer(0)); |
| 472 | this->Copy(varid, startp, countp, dst); |
| 473 | } |
| 474 | return NC_NOERR; |
| 475 | } |
| 476 | |
| 477 | int vtkXArrayAccessor::get_vars(int vtkNotUsed(ncid), int varid, const size_t* startp, |
| 478 | const size_t* countp, const ptrdiff_t* vtkNotUsed(stridep), void* ip) |
no test coverage detected