Skip to content

Commit e26c778

Browse files
committed
Fix crash on invalid config
1 parent fa36bff commit e26c778

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

indi-asi/asi_base.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,8 @@ bool ASIBase::initProperties()
390390

391391
// Add Debug and Nickname Controls from DefaultDevice.
392392
addDebugControl();
393-
if (!mSerialNumber.empty()) {
393+
if (!mSerialNumber.empty())
394+
{
394395
// asi_single_ccd does not set serial number
395396
addNicknameControl();
396397
}
@@ -1014,13 +1015,22 @@ bool ASIBase::ISNewSwitch(const char *dev, const char *name, ISState *states, ch
10141015

10151016
void ASIBase::nicknameSet(const char *nickname)
10161017
{
1017-
if (!mSerialNumber.empty()) {
1018+
if (!mSerialNumber.empty())
1019+
{
10181020
saveNicknameId(nickname, mSerialNumber.c_str());
10191021
}
10201022
}
10211023

10221024
bool ASIBase::setVideoFormat(uint8_t index)
10231025
{
1026+
// Guard against out-of-bounds index (e.g. stale/corrupt saved config)
1027+
if (VideoFormatSP.isEmpty() || index >= VideoFormatSP.count())
1028+
{
1029+
LOGF_WARN("Invalid video format index %d (max %d), ignoring.", index,
1030+
VideoFormatSP.isEmpty() ? 0 : VideoFormatSP.count() - 1);
1031+
return false;
1032+
}
1033+
10241034
auto currentFormat = getImageType();
10251035
// If requested type is 16bit but we are already on 8bit and camera is 120, then ignore request
10261036
if (currentFormat != ASI_IMG_RAW16 && index == ASI_IMG_RAW16 && (strstr(getDeviceName(), "ASI120")

0 commit comments

Comments
 (0)