Adding checks around the value cache in the IPMI update (#1054) (#1061)

* Adding checks around the value cache in the IPMI update to prevent null dereference.

* Adding braces for code style.

---------

Co-authored-by: doolbneerg <doolbneerg@outlook.com>
This commit is contained in:
Derek M
2023-04-30 10:30:21 +02:00
committed by GitHub
co-authored by doolbneerg
parent 0d796c6f44
commit ac4db9d4b9
@@ -174,21 +174,21 @@ internal class Ipmi : ISuperIO
{
case 1:
_temperatures.Add(RawToFloat(reading[1], sdr));
if (Temperatures.Length == 0)
if (Temperatures == null || Temperatures.Length == 0)
_temperatureNames.Add(sdr.id_string.Replace(" Temp", ""));
break;
case 2:
_voltages.Add(RawToFloat(reading[1], sdr));
if (Voltages.Length == 0)
if (Voltages == null || Voltages.Length == 0)
_voltageNames.Add(sdr.id_string);
break;
case 4:
_fans.Add(RawToFloat(reading[1], sdr));
if (Fans.Length == 0)
if (Fans == null || Fans.Length == 0)
_fanNames.Add(sdr.id_string);
break;
@@ -213,17 +213,29 @@ internal class Ipmi : ISuperIO
}
}
for (int i = 0; i < Math.Min(_temperatures.Count, Temperatures.Length); ++i)
Temperatures[i] = _temperatures[i];
if (Temperatures != null)
{
for (int i = 0; i < Math.Min(_temperatures.Count, Temperatures.Length); ++i)
Temperatures[i] = _temperatures[i];
}
for (int i = 0; i < Math.Min(_voltages.Count, Voltages.Length); ++i)
Voltages[i] = _voltages[i];
if (Voltages != null)
{
for (int i = 0; i < Math.Min(_voltages.Count, Voltages.Length); ++i)
Voltages[i] = _voltages[i];
}
for (int i = 0; i < Math.Min(_fans.Count, Fans.Length); ++i)
Fans[i] = _fans[i];
if (Fans != null)
{
for (int i = 0; i < Math.Min(_fans.Count, Fans.Length); ++i)
Fans[i] = _fans[i];
}
for (int i = 0; i < Math.Min(_controls.Count, Controls.Length); ++i)
Controls[i] = _controls[i];
if (Controls != null)
{
for (int i = 0; i < Math.Min(_controls.Count, Controls.Length); ++i)
Controls[i] = _controls[i];
}
}
public IEnumerable<Temperature> GetTemperatures()