mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-05-06 09:03:52 +00:00
fix: resolve all GitHub CodeQL security/quality alerts
Fix 9 integer-multiplication-cast-to-long warnings across 6 files: - wmo_renderer.cpp: grid cell count and height variance calculation - composite_renderer.cpp: overlay tile grid allocation - vk_texture.cpp: image size calculation (width*height*bpp) - m2_renderer.cpp: collision grid cell allocation - character_renderer.cpp: normal map buffer and height variance - world_entry_callback_handler.cpp: tile reserve count All fixes cast operands to size_t/double before multiplication to prevent integer overflow when dimensions are large.
This commit is contained in:
parent
d773109b50
commit
67f4097e74
6 changed files with 9 additions and 9 deletions
|
|
@ -108,7 +108,7 @@ static void precacheNearbyTiles(rendering::TerrainManager* terrainMgr,
|
|||
auto [tileX, tileY] = core::coords::worldToTile(renderPos.x, renderPos.y);
|
||||
int side = 2 * radius + 1;
|
||||
std::vector<std::pair<int,int>> tiles;
|
||||
tiles.reserve(side * side);
|
||||
tiles.reserve(static_cast<size_t>(side) * static_cast<size_t>(side));
|
||||
for (int dy = -radius; dy <= radius; dy++)
|
||||
for (int dx = -radius; dx <= radius; dx++)
|
||||
tiles.push_back({tileX + dx, tileY + dy});
|
||||
|
|
|
|||
|
|
@ -548,7 +548,7 @@ std::unique_ptr<VkTexture> CharacterRenderer::generateNormalHeightMap(
|
|||
if (!vkCtx_ || width == 0 || height == 0) return nullptr;
|
||||
|
||||
// Use the CPU-only static method, then upload to GPU
|
||||
std::vector<uint8_t> dummy(width * height * 4);
|
||||
std::vector<uint8_t> dummy(static_cast<size_t>(width) * static_cast<size_t>(height) * 4);
|
||||
std::memcpy(dummy.data(), pixels, dummy.size());
|
||||
auto result = generateNormalHeightMapCPU("", std::move(dummy), width, height);
|
||||
outVariance = result.variance;
|
||||
|
|
@ -585,7 +585,7 @@ CharacterRenderer::NormalMapResult CharacterRenderer::generateNormalHeightMapCPU
|
|||
float h = 0.299f * r + 0.587f * g + 0.114f * b;
|
||||
heightMap[i] = h;
|
||||
sumH += h;
|
||||
sumH2 += h * h;
|
||||
sumH2 += static_cast<double>(h) * static_cast<double>(h);
|
||||
}
|
||||
double mean = sumH / totalPixels;
|
||||
result.variance = static_cast<float>(sumH2 / totalPixels - mean * mean);
|
||||
|
|
|
|||
|
|
@ -1032,8 +1032,8 @@ void M2ModelGPU::CollisionMesh::build() {
|
|||
gridCellsX = std::max(1, std::min(32, static_cast<int>(std::ceil((bmax.x - bmin.x) / CELL_SIZE))));
|
||||
gridCellsY = std::max(1, std::min(32, static_cast<int>(std::ceil((bmax.y - bmin.y) / CELL_SIZE))));
|
||||
|
||||
cellFloorTris.resize(gridCellsX * gridCellsY);
|
||||
cellWallTris.resize(gridCellsX * gridCellsY);
|
||||
cellFloorTris.resize(static_cast<size_t>(gridCellsX) * static_cast<size_t>(gridCellsY));
|
||||
cellWallTris.resize(static_cast<size_t>(gridCellsX) * static_cast<size_t>(gridCellsY));
|
||||
triBounds.resize(triCount);
|
||||
|
||||
for (uint32_t ti = 0; ti < triCount; ti++) {
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ bool VkTexture::upload(VkContext& ctx, const uint8_t* pixels, uint32_t width, ui
|
|||
else if (format == VK_FORMAT_R8G8_UNORM) bpp = 2;
|
||||
else if (format == VK_FORMAT_R8G8B8_UNORM) bpp = 3;
|
||||
|
||||
VkDeviceSize imageSize = width * height * bpp;
|
||||
VkDeviceSize imageSize = static_cast<VkDeviceSize>(width) * static_cast<VkDeviceSize>(height) * bpp;
|
||||
|
||||
// Create staging buffer
|
||||
AllocatedBuffer staging = createBuffer(ctx.getAllocator(), imageSize,
|
||||
|
|
|
|||
|
|
@ -2248,7 +2248,7 @@ std::unique_ptr<VkTexture> WMORenderer::generateNormalHeightMap(
|
|||
float h = 0.299f * r + 0.587f * g + 0.114f * b;
|
||||
heightMap[i] = h;
|
||||
sumH += h;
|
||||
sumH2 += h * h;
|
||||
sumH2 += static_cast<double>(h) * static_cast<double>(h);
|
||||
}
|
||||
double mean = sumH / totalPixels;
|
||||
outVariance = static_cast<float>(sumH2 / totalPixels - mean * mean);
|
||||
|
|
@ -2716,7 +2716,7 @@ void WMORenderer::GroupResources::buildCollisionGrid() {
|
|||
if (gridCellsX > 64) gridCellsX = 64;
|
||||
if (gridCellsY > 64) gridCellsY = 64;
|
||||
|
||||
size_t totalCells = gridCellsX * gridCellsY;
|
||||
size_t totalCells = static_cast<size_t>(gridCellsX) * static_cast<size_t>(gridCellsY);
|
||||
cellTriangles.resize(totalCells);
|
||||
cellFloorTriangles.resize(totalCells);
|
||||
cellWallTriangles.resize(totalCells);
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ void CompositeRenderer::ensureTextureSlots(size_t zoneCount, const std::vector<Z
|
|||
slots.overlays.resize(zones[i].overlays.size());
|
||||
for (size_t oi = 0; oi < zones[i].overlays.size(); oi++) {
|
||||
const auto& ov = zones[i].overlays[oi];
|
||||
slots.overlays[oi].tiles.resize(ov.tileCols * ov.tileRows, nullptr);
|
||||
slots.overlays[oi].tiles.resize(static_cast<size_t>(ov.tileCols) * static_cast<size_t>(ov.tileRows), nullptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue