summaryrefslogtreecommitdiffstatshomepage
path: root/src/emu/rendersw.hxx
diff options
context:
space:
mode:
author hap <happppp@users.noreply.github.com>2023-12-26 16:54:24 +0100
committer hap <happppp@users.noreply.github.com>2023-12-26 16:54:24 +0100
commit642c89bd14853b9de8a0ca33d4179ecbd0e21a3f (patch)
tree4679bd5a8f86c293070bce79e1e50f0700ab3c24 /src/emu/rendersw.hxx
parent6ab5abe35de24b6e8ee3e1933b439441cae6279f (diff)
rendersw: add out of bounds check to 16-bit get_texel (32-bit version already has it)
Diffstat (limited to 'src/emu/rendersw.hxx')
-rw-r--r--src/emu/rendersw.hxx17
1 files changed, 13 insertions, 4 deletions
diff --git a/src/emu/rendersw.hxx b/src/emu/rendersw.hxx
index aa7b2253795..5561928e7df 100644
--- a/src/emu/rendersw.hxx
+++ b/src/emu/rendersw.hxx
@@ -153,7 +153,10 @@ private:
}
else
{
- u16 const *const texbase = reinterpret_cast<u16 const *>(texture.base) + (curv >> 16) * texture.rowpixels + (curu >> 16);
+ s32 u = std::clamp<s32>(curu >> 16, 0, texture.width - 1);
+ s32 v = std::clamp<s32>(curv >> 16, 0, texture.height - 1);
+
+ u16 const *const texbase = reinterpret_cast<u16 const *>(texture.base) + v * texture.rowpixels + u;
return palbase[texbase[0]];
}
}
@@ -185,7 +188,10 @@ private:
}
else
{
- u16 const *const texbase = reinterpret_cast<u16 const *>(texture.base) + (curv >> 16) * texture.rowpixels + (curu >> 16);
+ s32 u = std::clamp<s32>(curu >> 16, 0, texture.width - 1);
+ s32 v = std::clamp<s32>(curv >> 16, 0, texture.height - 1);
+
+ u16 const *const texbase = reinterpret_cast<u16 const *>(texture.base) + v * texture.rowpixels + u;
return palbase[texbase[0]];
}
}
@@ -247,8 +253,11 @@ private:
}
else
{
- const u16 *texbase = reinterpret_cast<const u16 *>(texture.base) + (curv >> 16) * texture.rowpixels + (curu >> 17) * 2;
- return (texbase[(curu >> 16) & 1] >> 8) | ((texbase[0] & 0xff) << 8) | ((texbase[1] & 0xff) << 16);
+ s32 u = std::clamp<s32>(curu >> 16, 0, texture.width - 1);
+ s32 v = std::clamp<s32>(curv >> 16, 0, texture.height - 1);
+
+ const u16 *texbase = reinterpret_cast<const u16 *>(texture.base) + v * texture.rowpixels + (u >> 1) * 2;
+ return (texbase[u & 1] >> 8) | ((texbase[0] & 0xff) << 8) | ((texbase[1] & 0xff) << 16);
}
}