1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-23 16:25:31 +03:00

Protect vtxCommonLookupXXX against null vtxDevice call

This commit is contained in:
jflyper 2019-01-17 13:52:51 +09:00
parent 80c1cfa6db
commit 53ab1ad23e

View file

@ -128,22 +128,35 @@ bool vtxCommonGetDeviceCapability(const vtxDevice_t *vtxDevice, vtxDeviceCapabil
const char *vtxCommonLookupBandName(const vtxDevice_t *vtxDevice, int band) const char *vtxCommonLookupBandName(const vtxDevice_t *vtxDevice, int band)
{ {
if (vtxDevice) {
return vtxDevice->bandNames[band]; return vtxDevice->bandNames[band];
} else {
return "?";
}
} }
char vtxCommonLookupBandLetter(const vtxDevice_t *vtxDevice, int band) char vtxCommonLookupBandLetter(const vtxDevice_t *vtxDevice, int band)
{ {
if (vtxDevice) {
return vtxDevice->bandLetters[band]; return vtxDevice->bandLetters[band];
} else {
return '?';
}
} }
const char *vtxCommonLookupChannelName(const vtxDevice_t *vtxDevice, int channel) const char *vtxCommonLookupChannelName(const vtxDevice_t *vtxDevice, int channel)
{ {
if (vtxDevice) {
return vtxDevice->channelNames[channel]; return vtxDevice->channelNames[channel];
} else {
return "?";
}
} }
//Converts frequency (in MHz) to band and channel values. //Converts frequency (in MHz) to band and channel values.
bool vtxCommonLookupBandChan(const vtxDevice_t *vtxDevice, uint16_t freq, uint8_t *pBand, uint8_t *pChannel) bool vtxCommonLookupBandChan(const vtxDevice_t *vtxDevice, uint16_t freq, uint8_t *pBand, uint8_t *pChannel)
{ {
if (vtxDevice) {
// Use reverse lookup order so that 5880Mhz // Use reverse lookup order so that 5880Mhz
// get Raceband 7 instead of Fatshark 8. // get Raceband 7 instead of Fatshark 8.
for (int band = vtxDevice->capability.bandCount - 1 ; band >= 0 ; band--) { for (int band = vtxDevice->capability.bandCount - 1 ; band >= 0 ; band--) {
@ -155,6 +168,7 @@ bool vtxCommonLookupBandChan(const vtxDevice_t *vtxDevice, uint16_t freq, uint8_
} }
} }
} }
}
*pBand = 0; *pBand = 0;
*pChannel = 0; *pChannel = 0;
@ -168,21 +182,31 @@ bool vtxCommonLookupBandChan(const vtxDevice_t *vtxDevice, uint16_t freq, uint8_
// Returns frequency value (in MHz), or 0 if band/channel out of range. // Returns frequency value (in MHz), or 0 if band/channel out of range.
uint16_t vtxCommonLookupFrequency(const vtxDevice_t *vtxDevice, int band, int channel) uint16_t vtxCommonLookupFrequency(const vtxDevice_t *vtxDevice, int band, int channel)
{ {
if (vtxDevice && band > 0 && band <= vtxDevice->capability.bandCount && if (vtxDevice) {
if (band > 0 && band <= vtxDevice->capability.bandCount &&
channel > 0 && channel <= vtxDevice->capability.channelCount) { channel > 0 && channel <= vtxDevice->capability.channelCount) {
return vtxDevice->frequencyTable[(band - 1) * vtxDevice->capability.channelCount + (channel - 1)]; return vtxDevice->frequencyTable[(band - 1) * vtxDevice->capability.channelCount + (channel - 1)];
} }
}
return 0; return 0;
} }
const char *vtxCommonLookupPowerName(const vtxDevice_t *vtxDevice, int index) const char *vtxCommonLookupPowerName(const vtxDevice_t *vtxDevice, int index)
{ {
if (vtxDevice) {
return vtxDevice->powerNames[index]; return vtxDevice->powerNames[index];
} else {
return "?";
}
} }
uint16_t vtxCommonLookupPowerValue(const vtxDevice_t *vtxDevice, int index) uint16_t vtxCommonLookupPowerValue(const vtxDevice_t *vtxDevice, int index)
{ {
if (vtxDevice) {
return vtxDevice->powerValues[index]; return vtxDevice->powerValues[index];
} else {
return 0;
}
} }
#endif #endif