@@ -819,8 +819,18 @@ namespace COMMON_NS
819819 case SOAP_TYPE_gsoap_resqml2_0_1_resqml20__IntegerRangeArray:
820820 {
821821 gsoap_resqml2_0_1::resqml20__IntegerRangeArray const * rangeArray = static_cast <gsoap_resqml2_0_1::resqml20__IntegerRangeArray const *>(arrayInput);
822- if (rangeArray->Value + rangeArray->Count > (std::numeric_limits<T>::max)()) {
823- throw std::range_error (" The range integer values are superior to maximum value of read datatype." );
822+ if constexpr (std::is_signed_v<T>) {
823+ if (rangeArray->Value < (std::numeric_limits<T>::min)()) {
824+ throw std::overflow_error (" Too low integers in XML for the C++ chosen datatype" );
825+ }
826+ }
827+ else {
828+ if (rangeArray->Value < 0 ) {
829+ throw std::underflow_error (" Cannot deal with negative values when using unsigned integer" );
830+ }
831+ }
832+ if (rangeArray->Value + rangeArray->Count > static_cast <uint64_t >((std::numeric_limits<T>::max)())) {
833+ throw std::overflow_error (" The range integer values are superior to maximum value of read datatype." );
824834 }
825835 for (T i = 0 ; i < static_cast <T>(rangeArray->Count ); ++i) {
826836 arrayOutput[i] = i + static_cast <T>(rangeArray->Value );
@@ -830,10 +840,17 @@ namespace COMMON_NS
830840 case SOAP_TYPE_gsoap_resqml2_0_1_resqml20__IntegerConstantArray:
831841 {
832842 gsoap_resqml2_0_1::resqml20__IntegerConstantArray const * constantArray = static_cast <gsoap_resqml2_0_1::resqml20__IntegerConstantArray const *>(arrayInput);
833- if (sizeof (constantArray->Value ) > sizeof (T) && constantArray->Value > (std::numeric_limits<T>::max)()) {
834- throw std::range_error (" The constant integer value is superior to maximum value of read datatype." );
843+ T value;
844+ if constexpr (std::is_signed_v<T>) {
845+ value = static_cast <T>(std::clamp (constantArray->Value ,
846+ static_cast <int64_t >((std::numeric_limits<T>::min)()), static_cast <int64_t >((std::numeric_limits<T>::max)())));
835847 }
836- std::fill (arrayOutput, arrayOutput + constantArray->Count , static_cast <T>(constantArray->Value ));
848+ else {
849+ value = constantArray->Value > 0
850+ ? static_cast <T>(std::clamp (static_cast <uint64_t >(constantArray->Value ), static_cast <uint64_t >(0 ), static_cast <uint64_t >((std::numeric_limits<T>::max)())))
851+ : (std::numeric_limits<T>::max)();
852+ }
853+ std::fill (arrayOutput, arrayOutput + constantArray->Count , value);
837854 return (std::numeric_limits<T>::max)();
838855 }
839856 case SOAP_TYPE_gsoap_resqml2_0_1_resqml20__BooleanConstantArray:
@@ -848,8 +865,22 @@ namespace COMMON_NS
848865 if (latticeArray->Offset .size () > 1 ) {
849866 throw std::invalid_argument (" The integer lattice array contains more than one offset." );
850867 }
851- for (size_t i = 0 ; i <= latticeArray->Offset [0 ]->Count ; ++i) {
852- arrayOutput[i] = latticeArray->StartValue + (i * latticeArray->Offset [0 ]->Value );
868+ if constexpr (std::is_signed_v<T>) {
869+ if (latticeArray->StartValue < (std::numeric_limits<T>::min)() || latticeArray->Offset [0 ]->Value < (std::numeric_limits<T>::min)()) {
870+ throw std::overflow_error (" Too low integers in XML for the C++ chosen datatype" );
871+ }
872+ }
873+ else {
874+ if (latticeArray->StartValue < 0 || latticeArray->Offset [0 ]->Value < 0 ) {
875+ throw std::underflow_error (" Cannot deal with negative values when using unsigned integer" );
876+ }
877+ }
878+ if (static_cast <T>(latticeArray->StartValue ) > (std::numeric_limits<T>::max)() ||
879+ static_cast <T>(latticeArray->Offset [0 ]->Value ) > (std::numeric_limits<T>::max)()) {
880+ throw std::overflow_error (" Too big integers in XML for the C++ chosen datatype" );
881+ }
882+ for (auto i = 0 ; i <= latticeArray->Offset [0 ]->Count ; ++i) {
883+ arrayOutput[i] = static_cast <T>(latticeArray->StartValue ) + (i * static_cast <T>(latticeArray->Offset [0 ]->Value ));
853884 }
854885 return (std::numeric_limits<T>::max)();
855886 }
0 commit comments