From 010590c66c478fe82614bf227e6043b87c2dc96a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABlle=20USSEGLIO?= <gaelle.usseglio@cnes.fr> Date: Tue, 20 Nov 2018 10:29:47 +0000 Subject: [PATCH] ENH : std::stoi instead of atoi --- .../src/ossim/ossimSentinel1Model.cpp | 23 +++++++++++++++++-- .../ossim/ossimSentinel1SarSensorModel.cpp | 23 +++++++++++++++++-- 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/Modules/ThirdParty/OssimPlugins/src/ossim/ossimSentinel1Model.cpp b/Modules/ThirdParty/OssimPlugins/src/ossim/ossimSentinel1Model.cpp index 213946dd57..7133a856fd 100644 --- a/Modules/ThirdParty/OssimPlugins/src/ossim/ossimSentinel1Model.cpp +++ b/Modules/ThirdParty/OssimPlugins/src/ossim/ossimSentinel1Model.cpp @@ -1025,7 +1025,17 @@ namespace ossimplugins // Find first valid samples if(*sIt!="-1") { - int Fvs = atoi((*sIt).c_str()); + int Fvs = samplesPerBurst; + try + { + Fvs = std::stoi(*sIt); + } + catch( ... ) + { + // Throw an execption + throw std::runtime_error("Failed to convert firstValidSample value."); + } + if (Fvs > first_sample_valid && Fvs < samplesPerBurst) { first_sample_valid = Fvs; @@ -1043,7 +1053,16 @@ namespace ossimplugins // Last first valid samples if(*sIt!="-1") { - int Lvs = atoi((*sIt).c_str()); + int Lvs = 0; + try + { + Lvs = std::stoi(*sIt); + } + catch( ... ) + { + // Throw an execption + throw std::runtime_error("Failed to convert lastValidSample value."); + } if (Lvs < last_sample_valid && Lvs > 0) { last_sample_valid = Lvs; diff --git a/Modules/ThirdParty/OssimPlugins/src/ossim/ossimSentinel1SarSensorModel.cpp b/Modules/ThirdParty/OssimPlugins/src/ossim/ossimSentinel1SarSensorModel.cpp index fbc7ee22e3..7f6cb886f7 100644 --- a/Modules/ThirdParty/OssimPlugins/src/ossim/ossimSentinel1SarSensorModel.cpp +++ b/Modules/ThirdParty/OssimPlugins/src/ossim/ossimSentinel1SarSensorModel.cpp @@ -237,7 +237,16 @@ void ossimSentinel1SarSensorModel::readAnnotationFile(const std::string & annota // Find first valid samples if(*sIt!="-1") { - int Fvs = atoi((*sIt).c_str()); + int Fvs = samplesPerBurst; + try + { + Fvs = std::stoi(*sIt); + } + catch( ... ) + { + // Throw an execption + throw std::runtime_error("Failed to convert firstValidSample value."); + } if (Fvs > first_sample_valid && Fvs < samplesPerBurst) { first_sample_valid = Fvs; @@ -255,7 +264,17 @@ void ossimSentinel1SarSensorModel::readAnnotationFile(const std::string & annota // Last first valid samples if(*sIt!="-1") { - int Lvs = atoi((*sIt).c_str()); + int Lvs = 0; + try + { + Lvs = std::stoi(*sIt); + } + catch( ... ) + { + // Throw an execption + throw std::runtime_error("Failed to convert lastValidSample value."); + } + if (Lvs < last_sample_valid && Lvs > 0) { last_sample_valid = Lvs; -- GitLab