Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 30 additions & 11 deletions interfaces/C++/TACDev/TACDev.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ unsigned long GetPortData
int result{0};

const AlpacaDevices& alpacaDevices = gDevTACCore.GetAlpacaDevices();
if (deviceIndex < alpacaDevices.count())
if (deviceIndex >= 0 && deviceIndex < alpacaDevices.count())
{
AlpacaDevice alpacaDevice = alpacaDevices.at(deviceIndex);
QByteArray portData2;
Expand Down Expand Up @@ -919,8 +919,13 @@ TAC_ERROR GetCommand
AlpacaDevice alpacaDevice = gDevTACCore.getAlpacaDevice(tacHandle);
if (alpacaDevice.isNull() == false)
{
TACCommand commandEntry = alpacaDevice->commandEntry(commandIndex);
if (commandEntry._pin != 0)
// commandEntry() returns a default entry (pin == -1) for an out-of-range index,
// so check the range explicitly instead of relying on the pin value.
TACCommand commandEntry;
const bool inRange = commandIndex < alpacaDevice->commandCount();
if (inRange)
commandEntry = alpacaDevice->commandEntry(commandIndex);
if (inRange && commandEntry._pin != 0)
{
QByteArray commandData;

Expand Down Expand Up @@ -1093,21 +1098,26 @@ TAC_ERROR GetHelpText
AlpacaDevice alpacaDevice = gDevTACCore.getAlpacaDevice(tacHandle);
if (alpacaDevice.isNull() == false)
{
// todo
QByteArray helpText = alpacaDevice->getHelp();
if (helpText.size() >= bufferSize)
{
result = TACDEV_BUFFER_TOO_SMALL;
gDevTACCore.setLastError(kTACDevBufferTooSmall);
*actualSize = helpText.size();
if (actualSize != nullptr)
*actualSize = helpText.size();
}
else
{
my_memcpy(helpBuffer, bufferSize, helpText, helpText.size());
if (actualSize != nullptr)
*actualSize = helpText.size();
}
}
else
{
my_memcpy(helpBuffer, bufferSize, "\0", 1);
*actualSize = 0;
if (actualSize != nullptr)
*actualSize = 0;

result = TACDEV_BAD_TAC_HANDLE;
gDevTACCore.setLastError(kTACDevHandleNotOpen);
Expand Down Expand Up @@ -1140,14 +1150,23 @@ TAC_ERROR GetScriptVariable(TAC_HANDLE tacHandle, unsigned long scriptVariableIn

if (alpacaDevice.isNull() == false)
{
QByteArray variableData = alpacaDevice->getScriptVariable(scriptVariableIndex);
if (variableData.size() >= bufferSize)
if (scriptVariableIndex >= alpacaDevice->scriptVariableCount())
{
result = TACDEV_BUFFER_TOO_SMALL;
gDevTACCore.setLastError(kTACDevBufferTooSmall);
my_memcpy(scriptVariableBuffer, bufferSize, "\0", 1);
result = TAC_BAD_INDEX;
gDevTACCore.setLastError(kTACBadIndex);
}
else
my_memcpy(scriptVariableBuffer, bufferSize, variableData, variableData.size());
{
QByteArray variableData = alpacaDevice->getScriptVariable(scriptVariableIndex);
if (variableData.size() >= bufferSize)
{
result = TACDEV_BUFFER_TOO_SMALL;
gDevTACCore.setLastError(kTACDevBufferTooSmall);
}
else
my_memcpy(scriptVariableBuffer, bufferSize, variableData, variableData.size());
}
}
else
{
Expand Down
Loading