improved index out of range diagnostics

This commit is contained in:
2025-11-16 09:25:09 +01:00
parent 898645ed94
commit 5f74028ab6
3 changed files with 18 additions and 0 deletions

8
mat.h
View File

@@ -744,6 +744,7 @@ template <typename T>
inline T* NRMat<T>::operator[](const int i) {
#ifdef DEBUG
if (_LA_count_check && *count != 1) laerror("matrix with *count>1 used as l-value");
if(i<0||i>=nn) std::cout<<"INDEX PROBLEM "<<0<<" "<<i<<" "<<nn-1<<std::endl;
if (i < 0) laerror("Mat [] out of range - low");
if (i >= nn) laerror("Mat [] out of range - high");
if (!v) laerror("unallocated matrix");
@@ -762,6 +763,7 @@ inline T* NRMat<T>::operator[](const int i) {
template <typename T>
inline const T* NRMat<T>::operator[](const int i) const {
#ifdef DEBUG
if(i<0||i>=nn) std::cout<<"INDEX PROBLEM "<<0<<" "<<i<<" "<<nn-1<<std::endl;
if (i < 0) laerror("index out of range - low");
if (i >= nn) laerror("index out of range - high");
if (!v) laerror("unallocated matrix");
@@ -785,6 +787,7 @@ template <typename T>
inline T& NRMat<T>::operator()(const int i, const int j){
#ifdef DEBUG
if (_LA_count_check && *count != 1) laerror("NRMat::operator(,) used as l-value for a matrix with count > 1");
if(i<0||i>=nn||j<0||j>mm) std::cout<<"INDEX PROBLEM "<<0<<" "<<i<<" "<<nn-1<<" "<<0<<" "<<j<<" "<<mm-1<<std::endl;
if (i < 0) laerror("first index out of range - low");
if (i >= nn) laerror("first index out of range - high");
if (j < 0) laerror("second index out of range - low");
@@ -809,6 +812,7 @@ template <typename T>
inline const T& NRMat<T>::operator()(const int i, const int j) const{
T ret;
#ifdef DEBUG
if(i<0||i>=nn||j<0||j>mm) std::cout<<"INDEX PROBLEM "<<0<<" "<<i<<" "<<nn-1<<" "<<0<<" "<<j<<" "<<mm-1<<std::endl;
if (i < 0) laerror("first index out of range - low");
if (i >= nn) laerror("first index out of range - high");
if (j < 0) laerror("second index out of range - low");
@@ -833,6 +837,7 @@ template <typename T>
inline const T NRMat<T>::get_ij(const int i, const int j) const{
T ret;
#ifdef DEBUG
if(i<0||i>=nn||j<0||j>mm) std::cout<<"INDEX PROBLEM "<<0<<" "<<i<<" "<<nn-1<<" "<<0<<" "<<j<<" "<<mm-1<<std::endl;
if (i < 0) laerror("first index out of range - low");
if (i >= nn) laerror("first index out of range - high");
if (j < 0) laerror("second index out of range - low");
@@ -1399,6 +1404,7 @@ public:
inline const T& operator() (const int i, const int j) const {
#ifdef DEBUG
if(i<=0||i>NRMat<T>::nn||j<=0||j>NRMat<T>::mm) std::cout<<"INDEX PROBLEM "<<1<<" "<<i<<" "<<NRMat<T>::nn<<" "<<1<<" "<<j<<" "<<NRMat<T>::mm<<std::endl;
if (i < 1) laerror("first index out of range - low");
if (i > NRMat<T>::nn) laerror("first index out of range - high");
if (j < 1) laerror("second index out of range - low");
@@ -1416,6 +1422,7 @@ public:
inline T& operator() (const int i, const int j) {
#ifdef DEBUG
if (_LA_count_check && *NRMat<T>::count != 1) laerror("matrix with *count > 1 used as l-value");
if(i<=0||i>NRMat<T>::nn||j<=0||j>NRMat<T>::mm) std::cout<<"INDEX PROBLEM "<<1<<" "<<i<<" "<<NRMat<T>::nn<<" "<<1<<" "<<j<<" "<<NRMat<T>::mm<<std::endl;
if (i < 1) laerror("first index out of range - low");
if (i > NRMat<T>::nn) laerror("first index out of range - high");
if (j < 1) laerror("second index out of range - low");
@@ -1433,6 +1440,7 @@ public:
inline const T get_ij(const int i, const int j) const {
T ret;
#ifdef DEBUG
if(i<=0||i>NRMat<T>::nn||j<=0||j>NRMat<T>::mm) std::cout<<"INDEX PROBLEM "<<1<<" "<<i<<" "<<NRMat<T>::nn<<" "<<1<<" "<<j<<" "<<NRMat<T>::mm<<std::endl;
if (i < 1) laerror("first index out of range - low");
if (i > NRMat<T>::nn) laerror("first index out of range - high");
if (j < 1) laerror("second index out of range - low");

6
smat.h
View File

@@ -626,6 +626,7 @@ template <typename T>
inline T& NRSMat<T>::operator[](const size_t ij) {
#ifdef DEBUG
if(_LA_count_check && *count != 1) laerror("T& NRSMat<T>::operator[] used for matrix with count>1");
if(ij<0||ij>=NN2) std::cout<<"INDEX PROBLEM "<<0<<" "<<ij<<" "<<NN2-1<<std::endl;
if(ij<0) laerror("T& NRSMat<T>::operator[] out of range - low");
if(ij>=NN2) laerror("T& NRSMat<T>::operator[] out of range - high");
if(!v) laerror("T& NRSMat<T>::operator[] used for unallocated NRSmat<T> object");
@@ -646,6 +647,7 @@ inline T& NRSMat<T>::operator[](const size_t ij) {
template <typename T>
inline const T & NRSMat<T>::operator[](const size_t ij) const {
#ifdef DEBUG
if(ij<0||ij>=NN2) std::cout<<"INDEX PROBLEM "<<0<<" "<<ij<<" "<<NN2-1<<std::endl;
if(ij<0) laerror("T& NRSMat<T>::operator[] out of range - low");
if(ij>=NN2) laerror("T& NRSMat<T>::operator[] out of range - high");
if(!v) laerror("T& NRSMat<T>::operator[] used for unallocated NRSmat<T> object");
@@ -754,6 +756,7 @@ template <typename T>
inline T & NRSMat<T>::operator()(const int i, const int j) {
#ifdef DEBUG
if(_LA_count_check && *count != 1) laerror("T & NRSMat<T>::operator()(const int, const int) used for matrix with count > 1");
if(i<0||i>=nn||j<0||j>=nn) std::cout<<"INDEX PROBLEM "<<0<<" "<<i<<" "<<nn-1<<" "<<0<<" "<<j<<" "<<nn-1<<std::endl;
if(i<0) laerror("T & NRSMat<T>::operator()(const int, const int) first index out of range - low");
if(i>=nn) laerror("T & NRSMat<T>::operator()(const int, const int) first index out of range - high");
if(j<0) laerror("T & NRSMat<T>::operator()(const int, const int) second index out of range - low");
@@ -775,6 +778,7 @@ inline T & NRSMat<T>::operator()(const int i, const int j) {
template <typename T>
inline const T & NRSMat<T>::operator()(const int i, const int j) const {
#ifdef DEBUG
if(i<0||i>=nn||j<0||j>=nn) std::cout<<"INDEX PROBLEM "<<0<<" "<<i<<" "<<nn-1<<" "<<0<<" "<<j<<" "<<nn-1<<std::endl;
if(i<0) laerror("T & NRSMat<T>::operator()(const int, const int) first index out of range - low");
if(i>=nn) laerror("T & NRSMat<T>::operator()(const int, const int) first index out of range - high");
if(j<0) laerror("T & NRSMat<T>::operator()(const int, const int) second index out of range - low");
@@ -1313,6 +1317,7 @@ public:
inline const T& operator() (const int i, const int j) const {
#ifdef DEBUG
if(i<=0||i>NRSMat<T>::nn||j<=0||j>NRSMat<T>::nn) std::cout<<"INDEX PROBLEM "<<1<<" "<<i<<" "<<NRSMat<T>::nn<<" "<<1<<" "<<j<<" "<<NRSMat<T>::nn<<std::endl;
if(i<=0) laerror("index in const T& NRSMat_from1<T>::operator() (const int, const int) first indexout of range - low");
if(i>NRSMat<T>::nn) laerror("index in const T& NRSMat_from1<T>::operator() (const int, const int) first indexout of range - high");
if(j<=0) laerror("index in const T& NRSMat_from1<T>::operator() (const int, const int) second index out of range - low");
@@ -1323,6 +1328,7 @@ public:
inline T& operator() (const int i, const int j){
#ifdef DEBUG
if(i<=0||i>NRSMat<T>::nn||j<=0||j>NRSMat<T>::nn) std::cout<<"INDEX PROBLEM "<<1<<" "<<i<<" "<<NRSMat<T>::nn<<" "<<1<<" "<<j<<" "<<NRSMat<T>::nn<<std::endl;
if(i<=0) laerror("index in const T& NRSMat_from1<T>::operator() (const int, const int) first indexout of range - low");
if(i>NRSMat<T>::nn) laerror("index in const T& NRSMat_from1<T>::operator() (const int, const int) first indexout of range - high");
if(j<=0) laerror("index in const T& NRSMat_from1<T>::operator() (const int, const int) second index out of range - low");

4
vec.h
View File

@@ -620,6 +620,7 @@ template <typename T>
inline T& NRVec_from1<T>::operator[](const int i) {
#ifdef DEBUG
if(_LA_count_check && *NRVec<T>::count != 1) laerror("possible use of NRVec[] with count>1 as l-value");
if(i<1||i > NRVec<T>::nn) std::cout<<"INDEX PROBLEM "<<1<<" "<<i<<" "<< NRVec<T>::nn<<std::endl;
if(i < 1) laerror("out of range - low");
if(i > NRVec<T>::nn) laerror("out of range - high");
if(!NRVec<T>::v) laerror("unallocated NRVec");
@@ -638,6 +639,7 @@ inline T& NRVec_from1<T>::operator[](const int i) {
template <typename T>
inline const T& NRVec_from1<T>::operator[](const int i) const {
#ifdef DEBUG
if(i<1||i > NRVec<T>::nn) std::cout<<"INDEX PROBLEM "<<1<<" "<<i<<" "<< NRVec<T>::nn<<std::endl;
if(i < 1) laerror("out of range - low");
if(i > NRVec<T>::nn) laerror("out of range - high");
if(!NRVec<T>::v) laerror("unallocated NRVec");
@@ -1082,6 +1084,7 @@ template <typename T>
inline T& NRVec<T>::operator[](const int i) {
#ifdef DEBUG
if(_LA_count_check && *count != 1) laerror("possible use of NRVec[] with count>1 as l-value");
if(i<0||i >= nn) std::cout<<"INDEX PROBLEM "<<0<<" "<<i<<" "<<nn-1<<std::endl;
if(i < 0) laerror("out of range - low");
if(i >= nn) laerror("out of range - high");
if(!v) laerror("unallocated NRVec");
@@ -1100,6 +1103,7 @@ inline T& NRVec<T>::operator[](const int i) {
template <typename T>
inline const T& NRVec<T>::operator[](const int i) const {
#ifdef DEBUG
if(i<0||i >= nn) std::cout<<"INDEX PROBLEM "<<0<<" "<<i<<" "<<nn-1<<std::endl;
if(i < 0) laerror("out of range - low");
if(i >= nn) laerror("out of range - high");
if(!v) laerror("unallocated NRVec");