From 0162b1d2bcd96b7e9c83eea51de49dae61150be3 Mon Sep 17 00:00:00 2001 From: f4exb Date: Wed, 21 Feb 2018 13:27:10 +0100 Subject: [PATCH] Web API: fixed missing initializations of error object --- sdrgui/webapi/webapiadaptergui.cpp | 13 ++++--------- sdrsrv/webapi/webapiadaptersrv.cpp | 12 ++++-------- 2 files changed, 8 insertions(+), 17 deletions(-) diff --git a/sdrgui/webapi/webapiadaptergui.cpp b/sdrgui/webapi/webapiadaptergui.cpp index 4cd81f288..d1a74600a 100644 --- a/sdrgui/webapi/webapiadaptergui.cpp +++ b/sdrgui/webapi/webapiadaptergui.cpp @@ -779,6 +779,8 @@ int WebAPIAdapterGUI::devicesetDeviceSettingsGet( SWGSDRangel::SWGDeviceSettings& response, SWGSDRangel::SWGErrorResponse& error) { + error.init(); + if ((deviceSetIndex >= 0) && (deviceSetIndex < (int) m_mainWindow.m_deviceUIs.size())) { DeviceUISet *deviceSet = m_mainWindow.m_deviceUIs[deviceSetIndex]; @@ -799,16 +801,13 @@ int WebAPIAdapterGUI::devicesetDeviceSettingsGet( } else { - error.init(); *error.getMessage() = QString("DeviceSet error"); return 500; } } else { - error.init(); *error.getMessage() = QString("There is no device set with index %1").arg(deviceSetIndex); - return 404; } } @@ -820,6 +819,8 @@ int WebAPIAdapterGUI::devicesetDeviceSettingsPutPatch( SWGSDRangel::SWGDeviceSettings& response, SWGSDRangel::SWGErrorResponse& error) { + error.init(); + if ((deviceSetIndex >= 0) && (deviceSetIndex < (int) m_mainWindow.m_deviceUIs.size())) { DeviceUISet *deviceSet = m_mainWindow.m_deviceUIs[deviceSetIndex]; @@ -828,13 +829,11 @@ int WebAPIAdapterGUI::devicesetDeviceSettingsPutPatch( { if (response.getTx() != 0) { - error.init(); *error.getMessage() = QString("Rx device found but Tx device requested"); return 400; } if (deviceSet->m_deviceSourceAPI->getHardwareId() != *response.getDeviceHwType()) { - error.init(); *error.getMessage() = QString("Device mismatch. Found %1 input").arg(deviceSet->m_deviceSourceAPI->getHardwareId()); return 400; } @@ -848,13 +847,11 @@ int WebAPIAdapterGUI::devicesetDeviceSettingsPutPatch( { if (response.getTx() == 0) { - error.init(); *error.getMessage() = QString("Tx device found but Rx device requested"); return 400; } else if (deviceSet->m_deviceSinkAPI->getHardwareId() != *response.getDeviceHwType()) { - error.init(); *error.getMessage() = QString("Device mismatch. Found %1 output").arg(deviceSet->m_deviceSinkAPI->getHardwareId()); return 400; } @@ -866,14 +863,12 @@ int WebAPIAdapterGUI::devicesetDeviceSettingsPutPatch( } else { - error.init(); *error.getMessage() = QString("DeviceSet error"); return 500; } } else { - error.init(); *error.getMessage() = QString("There is no device set with index %1").arg(deviceSetIndex); return 404; } diff --git a/sdrsrv/webapi/webapiadaptersrv.cpp b/sdrsrv/webapi/webapiadaptersrv.cpp index e7993170d..e192261e9 100644 --- a/sdrsrv/webapi/webapiadaptersrv.cpp +++ b/sdrsrv/webapi/webapiadaptersrv.cpp @@ -884,6 +884,8 @@ int WebAPIAdapterSrv::devicesetDeviceSettingsGet( SWGSDRangel::SWGDeviceSettings& response, SWGSDRangel::SWGErrorResponse& error) { + error.init(); + if ((deviceSetIndex >= 0) && (deviceSetIndex < (int) m_mainCore.m_deviceSets.size())) { DeviceSet *deviceSet = m_mainCore.m_deviceSets[deviceSetIndex]; @@ -904,14 +906,12 @@ int WebAPIAdapterSrv::devicesetDeviceSettingsGet( } else { - error.init(); *error.getMessage() = QString("DeviceSet error"); return 500; } } else { - error.init(); *error.getMessage() = QString("There is no device set with index %1").arg(deviceSetIndex); return 404; } @@ -924,6 +924,8 @@ int WebAPIAdapterSrv::devicesetDeviceSettingsPutPatch( SWGSDRangel::SWGDeviceSettings& response, SWGSDRangel::SWGErrorResponse& error) { + error.init(); + if ((deviceSetIndex >= 0) && (deviceSetIndex < (int) m_mainCore.m_deviceSets.size())) { DeviceSet *deviceSet = m_mainCore.m_deviceSets[deviceSetIndex]; @@ -932,13 +934,11 @@ int WebAPIAdapterSrv::devicesetDeviceSettingsPutPatch( { if (response.getTx() != 0) { - error.init(); *error.getMessage() = QString("Rx device found but Tx device requested"); return 400; } if (deviceSet->m_deviceSourceAPI->getHardwareId() != *response.getDeviceHwType()) { - error.init(); *error.getMessage() = QString("Device mismatch. Found %1 input").arg(deviceSet->m_deviceSourceAPI->getHardwareId()); return 400; } @@ -952,13 +952,11 @@ int WebAPIAdapterSrv::devicesetDeviceSettingsPutPatch( { if (response.getTx() == 0) { - error.init(); *error.getMessage() = QString("Tx device found but Rx device requested"); return 400; } else if (deviceSet->m_deviceSinkAPI->getHardwareId() != *response.getDeviceHwType()) { - error.init(); *error.getMessage() = QString("Device mismatch. Found %1 output").arg(deviceSet->m_deviceSinkAPI->getHardwareId()); return 400; } @@ -970,14 +968,12 @@ int WebAPIAdapterSrv::devicesetDeviceSettingsPutPatch( } else { - error.init(); *error.getMessage() = QString("DeviceSet error"); return 500; } } else { - error.init(); *error.getMessage() = QString("There is no device set with index %1").arg(deviceSetIndex); return 404; }