mirror of
https://github.com/CalcProgrammer1/OpenRGB.git
synced 2026-04-12 10:01:18 -04:00
Prevent division by zero crash in QMK OpenRGB controllers
This commit is contained in:
committed by
Adam Honse
parent
d5db3d6428
commit
9fd352efc4
@@ -525,6 +525,15 @@ unsigned int RGBController_QMKOpenRGBRev9::CalculateDivisor
|
||||
counts[i]++;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Guard against empty distances (malformed LED data) |
|
||||
\*---------------------------------------------------------*/
|
||||
if(distances.empty())
|
||||
{
|
||||
LOG_WARNING("[%s] No valid LED distances found, using default divisor of 1", name.c_str());
|
||||
return 1;
|
||||
}
|
||||
|
||||
unsigned int divisor = distances[0];
|
||||
for(const std::pair<const int, int> &i : counts)
|
||||
{
|
||||
@@ -533,6 +542,13 @@ unsigned int RGBController_QMKOpenRGBRev9::CalculateDivisor
|
||||
divisor = i.first;
|
||||
}
|
||||
}
|
||||
|
||||
if(divisor == 0)
|
||||
{
|
||||
LOG_WARNING("[%s] Calculated divisor is 0, using default of 1. This may indicate malformed LED position data.", name.c_str());
|
||||
return 1;
|
||||
}
|
||||
|
||||
return divisor;
|
||||
}
|
||||
|
||||
|
||||
@@ -560,6 +560,16 @@ unsigned int RGBController_QMKOpenRGBRevB::CalculateDivisor
|
||||
last_pos = pt.x;
|
||||
});
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Guard against empty distances (malformed LED data) |
|
||||
\*---------------------------------------------------------*/
|
||||
if(distances.empty())
|
||||
{
|
||||
LOG_WARNING("[%s] No valid LED distances found, using default divisor of 1", name.c_str());
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::map<int, int> counts;
|
||||
for(const int &i : distances)
|
||||
{
|
||||
@@ -574,6 +584,16 @@ unsigned int RGBController_QMKOpenRGBRevB::CalculateDivisor
|
||||
divisor = i.first;
|
||||
}
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Guard against zero divisor (prevents division by zero) |
|
||||
\*---------------------------------------------------------*/
|
||||
if(divisor == 0)
|
||||
{
|
||||
LOG_WARNING("[%s] Calculated divisor is 0, using default of 1. This may indicate malformed LED position data.", name.c_str());
|
||||
return 1;
|
||||
}
|
||||
|
||||
return divisor;
|
||||
}
|
||||
|
||||
|
||||
@@ -567,6 +567,15 @@ unsigned int RGBController_QMKOpenRGBRevD::CalculateDivisor
|
||||
counts[i]++;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Guard against empty distances (malformed LED data) |
|
||||
\*---------------------------------------------------------*/
|
||||
if(distances.empty())
|
||||
{
|
||||
LOG_WARNING("[%s] No valid LED distances found, using default divisor of 1", name.c_str());
|
||||
return 1;
|
||||
}
|
||||
|
||||
unsigned int divisor = distances[0];
|
||||
for(const std::pair<const int, int> &i : counts)
|
||||
{
|
||||
@@ -575,6 +584,13 @@ unsigned int RGBController_QMKOpenRGBRevD::CalculateDivisor
|
||||
divisor = i.first;
|
||||
}
|
||||
}
|
||||
|
||||
if(divisor == 0)
|
||||
{
|
||||
LOG_WARNING("[%s] Calculated divisor is 0, using default of 1. This may indicate malformed LED position data.", name.c_str());
|
||||
return 1;
|
||||
}
|
||||
|
||||
return divisor;
|
||||
}
|
||||
|
||||
|
||||
@@ -583,6 +583,15 @@ unsigned int RGBController_QMKOpenRGBRevE::CalculateDivisor
|
||||
counts[i]++;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Guard against empty distances (malformed LED data) |
|
||||
\*---------------------------------------------------------*/
|
||||
if(distances.empty())
|
||||
{
|
||||
LOG_WARNING("[%s] No valid LED distances found, using default divisor of 1", name.c_str());
|
||||
return 1;
|
||||
}
|
||||
|
||||
unsigned int divisor = distances[0];
|
||||
for(const std::pair<const int, int> &i : counts)
|
||||
{
|
||||
@@ -591,6 +600,13 @@ unsigned int RGBController_QMKOpenRGBRevE::CalculateDivisor
|
||||
divisor = i.first;
|
||||
}
|
||||
}
|
||||
|
||||
if(divisor == 0)
|
||||
{
|
||||
LOG_WARNING("[%s] Calculated divisor is 0, using default of 1. This may indicate malformed LED position data.", name.c_str());
|
||||
return 1;
|
||||
}
|
||||
|
||||
return divisor;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user