Fix `-Wsign-compare` warnings
MODIFY
src/inireader.cpp
src/inireader.cpp
@@ -87,7 +87,7 @@ INIReader::INIReader(std::istream& filestream)
int to_copy = num - 1;
- if (out.size() < num) {
+ if (out.size() < (size_t)num) {
to_copy = (int)out.size();
}

MODIFY
src/reader_util.h
src/reader_util.h
@@ -120,7 +120,12 @@ namespace ReaderUtil {
*/
template<typename T>
T* GetElement(std::vector<T>& vec, int one_based_index) {
- if (one_based_index < 1 || one_based_index > vec.size()) {
+ if (one_based_index < 1) {
+ return nullptr;
+ }
+
+ // index is nonnegative, safe to cast
+ if (static_cast<typename std::vector<T>::size_type>(one_based_index) > vec.size()) {
return nullptr;
}
@@ -137,7 +142,12 @@ namespace ReaderUtil {
*/
template<typename T>
const T* GetElement(const std::vector<T>& vec, int one_based_index) {
- if (one_based_index < 1 || one_based_index > vec.size()) {
+ if (one_based_index < 1) {
+ return nullptr;
+ }
+
+ // index is nonnegative, safe to cast
+ if (static_cast<typename std::vector<T>::size_type>(one_based_index) > vec.size()) {
return nullptr;
}

Fix `-Wsign-compare` warnings