🐛 Reject out-of-range hue lookups

The modulo silently wrapped invalid IDs to a wrong hue group instead
of failing.
This commit is contained in:
2026-11-15 22:06:51 +01:00
parent d41520eca4
commit 81f837a746
+4
View File
@@ -92,6 +92,8 @@ function THueProvider.GetData(AID, AOffset: Integer): TMulBlock;
var
group, entry: Integer;
begin
if (AID < 0) or (AID >= FHueGroups.Count * 8) then
raise Exception.CreateFmt('Invalid hue ID %d', [AID]);
group := (AID div 8) mod FHueGroups.Count;
entry := AID mod 8;
Result := TMulBlock(THueGroup(FHueGroups.Items[group]).HueEntries[entry].Clone);
@@ -104,6 +106,8 @@ function THueProvider.GetHue(AIndex: Integer): THue;
var
group, entry: Integer;
begin
if (AIndex < 0) or (AIndex >= FHueGroups.Count * 8) then
raise Exception.CreateFmt('Invalid hue ID %d', [AIndex]);
group := (AIndex div 8) mod FHueGroups.Count;
entry := AIndex mod 8;
Result := THue(THueGroup(FHueGroups.Items[group]).HueEntries[entry]);