From 900ac9a087d46f398a384457dee58c974854f9eb Mon Sep 17 00:00:00 2001 From: Tim Coalson Date: Wed, 27 Jul 2016 22:42:02 -0500 Subject: [PATCH] remove asserts from most headers (MultiDimArray and CompactLookup don't get called into from headers, so they should be okay) --- src/Cifti/VolumeSpace.cxx | 1 + src/Cifti/VolumeSpace.h | 2 -- src/Common/XmlAdapter.h | 5 ++--- src/NiftiIO.h | 25 ++++++++++++++++--------- 4 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/Cifti/VolumeSpace.cxx b/src/Cifti/VolumeSpace.cxx index 1a28a85..3152a9c 100644 --- a/src/Cifti/VolumeSpace.cxx +++ b/src/Cifti/VolumeSpace.cxx @@ -27,6 +27,7 @@ #include "VolumeSpace.h" +#include "Common/CiftiAssert.h" #include "Common/CiftiException.h" #include "Common/FloatMatrix.h" diff --git a/src/Cifti/VolumeSpace.h b/src/Cifti/VolumeSpace.h index 945ebcb..eb34df6 100644 --- a/src/Cifti/VolumeSpace.h +++ b/src/Cifti/VolumeSpace.h @@ -28,7 +28,6 @@ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "Common/CiftiAssert.h" #include "Common/Vector3D.h" #include "Common/XmlAdapter.h" @@ -129,7 +128,6 @@ namespace cifti inline int64_t getIndex(const int64_t& indexIn1, const int64_t& indexIn2, const int64_t& indexIn3) const { - CiftiAssert(indexValid(indexIn1, indexIn2, indexIn3)); return indexIn1 + m_dims[0] * (indexIn2 + m_dims[1] * indexIn3); } diff --git a/src/Common/XmlAdapter.h b/src/Common/XmlAdapter.h index 6275231..97c9d4a 100644 --- a/src/Common/XmlAdapter.h +++ b/src/Common/XmlAdapter.h @@ -51,7 +51,6 @@ namespace cifti #ifdef CIFTILIB_USE_XMLPP #define __XML_ADAPTER_H_HAVE_IMPL__ -#include "CiftiAssert.h" #include "libxml++/libxml++.h" #include "libxml++/parsers/textreader.h" #include "libxml/xmlwriter.h" @@ -101,7 +100,7 @@ namespace cifti } void writeEndElement() { - CiftiAssert(m_elementStack.size() > 0); + if (m_elementStack.empty()) throw CiftiException("internal error: attempted writing end element outside root element"); if (xmlTextWriterEndElement(m_xmlPtr) == -1) throw CiftiException("error writing end element for " + m_elementStack.back()); m_elementStack.pop_back(); } @@ -118,7 +117,7 @@ namespace cifti } void writeAttribute(const AString& name, const AString& text) { - CiftiAssert(m_elementStack.size() > 0); + if (m_elementStack.empty()) throw CiftiException("internal error: attempted writing attribute outside root element"); if (xmlTextWriterWriteAttribute(m_xmlPtr, BAD_CAST ASTRING_UTF8_RAW(name), BAD_CAST ASTRING_UTF8_RAW(text)) == -1) { throw CiftiException("error writing " + name + " attribute of " + m_elementStack.back() + " element"); diff --git a/src/NiftiIO.h b/src/NiftiIO.h index a5c37e6..490cada 100644 --- a/src/NiftiIO.h +++ b/src/NiftiIO.h @@ -31,7 +31,6 @@ #include "Common/AString.h" #include "Common/ByteSwapping.h" -#include "Common/CiftiAssert.h" #include "Common/BinaryFile.h" #include "Common/CiftiException.h" #include "Nifti/NiftiHeader.h" @@ -74,8 +73,12 @@ namespace cifti template void NiftiIO::readData(T* dataOut, const int& fullDims, const std::vector& indexSelect, const bool& tolerateShortRead) { - CiftiAssert(fullDims >= 0 && fullDims <= (int)m_dims.size()); - CiftiAssert((size_t)fullDims + indexSelect.size() == m_dims.size());//could be >=, but should catch more stupid mistakes as == + if (fullDims < 0) throw CiftiException("NiftiIO: fulldims must not be negative"); + if (fullDims > (int)m_dims.size()) throw CiftiException("NiftiIO: fulldims must not be greater than number of dimensions"); + if ((size_t)fullDims + indexSelect.size() != m_dims.size()) + {//could be >=, but should catch more stupid mistakes as == + throw CiftiException("NiftiIO: fulldims plus length of indexSelect must equal number of dimensions"); + } int64_t numElems = getNumComponents();//for now, calculate read size on the fly, as the read call will be the slowest part int curDim; for (curDim = 0; curDim < fullDims; ++curDim) @@ -85,7 +88,8 @@ namespace cifti int64_t numDimSkip = numElems, numSkip = 0; for (; curDim < (int)m_dims.size(); ++curDim) { - CiftiAssert(indexSelect[curDim - fullDims] >= 0 && indexSelect[curDim - fullDims] < m_dims[curDim]); + if (indexSelect[curDim - fullDims] < 0) throw CiftiException("NiftiIO: indices must not be negative"); + if (indexSelect[curDim - fullDims] >= m_dims[curDim]) throw CiftiException("NiftiIO: index exceeds nifti dimension length"); numSkip += indexSelect[curDim - fullDims] * numDimSkip; numDimSkip *= m_dims[curDim]; } @@ -137,7 +141,6 @@ namespace cifti convertRead(dataOut, (long double*)m_scratch.data(), numElems); break; default: - CiftiAssert(0); throw CiftiException("internal error, tell the developers what you just tried to do"); } } @@ -145,8 +148,12 @@ namespace cifti template void NiftiIO::writeData(const T* dataIn, const int& fullDims, const std::vector& indexSelect) { - CiftiAssert(fullDims >= 0 && fullDims <= (int)m_dims.size()); - CiftiAssert((size_t)fullDims + indexSelect.size() == m_dims.size());//could be >=, but should catch more stupid mistakes as == + if (fullDims < 0) throw CiftiException("NiftiIO: fulldims must not be negative"); + if (fullDims > (int)m_dims.size()) throw CiftiException("NiftiIO: fulldims must not be greater than number of dimensions"); + if ((size_t)fullDims + indexSelect.size() != m_dims.size()) + {//could be >=, but should catch more stupid mistakes as == + throw CiftiException("NiftiIO: fulldims plus length of indexSelect must equal number of dimensions"); + } int64_t numElems = getNumComponents();//for now, calculate read size on the fly, as the read call will be the slowest part int curDim; for (curDim = 0; curDim < fullDims; ++curDim) @@ -156,7 +163,8 @@ namespace cifti int64_t numDimSkip = numElems, numSkip = 0; for (; curDim < (int)m_dims.size(); ++curDim) { - CiftiAssert(indexSelect[curDim - fullDims] >= 0 && indexSelect[curDim - fullDims] < m_dims[curDim]); + if (indexSelect[curDim - fullDims] < 0) throw CiftiException("NiftiIO: indices must not be negative"); + if (indexSelect[curDim - fullDims] >= m_dims[curDim]) throw CiftiException("NiftiIO: index exceeds nifti dimension length"); numSkip += indexSelect[curDim - fullDims] * numDimSkip; numDimSkip *= m_dims[curDim]; } @@ -202,7 +210,6 @@ namespace cifti convertWrite((long double*)m_scratch.data(), dataIn, numElems); break; default: - CiftiAssert(0); throw CiftiException("internal error, tell the developers what you just tried to do"); } m_file.write(m_scratch.data(), m_scratch.size());