zink: avoid overflow when calculating size

If we multiply before we (implicitly) cast the result to the target
type, we needlessly risk overflowing the result.

CID: 1490790, 1475922

Reviewed-By: Mike Blumenkrantz <michael.blumenkrantz@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12559>
This commit is contained in:
Erik Faye-Lund
2021-08-25 21:44:46 +02:00
committed by Marge Bot
parent c96afa9fc8
commit e3239dff05
+2 -2
View File
@@ -1317,7 +1317,7 @@ zink_image_map(struct pipe_context *pctx,
(box->y / desc->block.height) * srl.rowPitch +
(box->x / desc->block.width) * (desc->block.bits / 8);
if (!res->obj->coherent) {
VkDeviceSize size = box->width * box->height * desc->block.bits / 8;
VkDeviceSize size = (VkDeviceSize)box->width * box->height * desc->block.bits / 8;
VkMappedMemoryRange range = zink_resource_init_mem_range(screen, res->obj, res->obj->offset + offset, size);
vkFlushMappedMemoryRanges(screen->dev, 1, &range);
}
@@ -1357,7 +1357,7 @@ zink_transfer_flush_region(struct pipe_context *pctx,
size = box->width;
offset = trans->offset;
} else {
size = box->width * box->height * util_format_get_blocksize(m->base.b.format);
size = (VkDeviceSize)box->width * box->height * util_format_get_blocksize(m->base.b.format);
offset = trans->offset +
box->z * trans->depthPitch +
util_format_get_2d_size(m->base.b.format, trans->base.b.stride, box->y) +