1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-07-30 19:23:07 +03:00

Fix -Wtype-limits

This commit is contained in:
Alexey Antipovsky
2020-11-10 18:23:21 +00:00
parent f4a6294c95
commit 0e29b0b0f9
11 changed files with 75 additions and 19 deletions

View File

@ -126,7 +126,7 @@ int SqlFileParser::Parse(const string& sqlfile)
throw length_error("SqlFileParser has file size hard limit of 16K.");
}
unsigned rcount;
std::streamsize rcount;
rcount = ifsql.readsome(sqlbuf, sizeof(sqlbuf) - 1);
if (rcount < 0)

View File

@ -148,7 +148,7 @@ int DMLFileParser::parse(const string& fileName)
throw length_error("DMLFileParser has file size hard limit of 16K.");
}
unsigned rcount;
std::streamsize rcount;
rcount = ifdml.readsome(dmlbuf, sizeof(dmlbuf) - 1);
if (rcount < 0)

View File

@ -65,6 +65,7 @@ using namespace rowgroup;
using namespace querytele;
#include "threadnaming.h"
#include "checks.h"
namespace joblist
{
@ -496,7 +497,7 @@ void pDictionaryScan::sendAPrimitiveMessage(
hdr.Hdr.Priority = priority();
hdr.LBID = msgLbidStart;
idbassert(hdr.LBID >= 0);
idbassert(utils::is_nonnegative(hdr.LBID));
hdr.OutputType = OT_TOKEN;
hdr.BOP = fBOP;
hdr.COP1 = fCOP1;

View File

@ -78,6 +78,8 @@ using namespace querytele;
#include "windowfunctionstep.h"
using namespace joblist;
#include "checks.h"
namespace
{
@ -722,7 +724,7 @@ void WindowFunctionStep::initialize(const RowGroup& rg, JobInfo& jobInfo)
string fn = boost::to_upper_copy(wc->functionName());
if ( (fn == "MEDIAN" || fn == "PERCENTILE_CONT" || fn == "PERCENTILE_DISC") &&
peerIdx[0] >= 0 && peerIdx[0] < types.size() )
utils::is_nonnegative(peerIdx[0]) && peerIdx[0] < types.size() )
ct = types[peerIdx[0]];
// create the functor based on function name

View File

@ -28,6 +28,7 @@ namespace bi = boost::interprocess;
#include "IDBPolicy.h"
#include "utils_utf8.h"
#include "crashtrace.h"
#include "checks.h"
using namespace std;
using namespace messageqcpp;
@ -2594,7 +2595,7 @@ void processStatusMSG(messageqcpp::IOSocket* cfIos)
}
}
if ( PID < 0 )
if (!utils::is_nonnegative(PID))
PID = 0;
log.writeLog(__LINE__, "statusControl: Set Process " + moduleName + "/" + processName + + " State = " + oamState[state] + " PID = " + oam.itoa(PID), LOG_TYPE_DEBUG);

View File

@ -29,6 +29,7 @@
#define BOOST_SPIRIT_THREADSAFE
#include <boost/property_tree/json_parser.hpp>
#include <iostream>
#include "checks.h"
#define max(x, y) (x > y ? x : y)
#define min(x, y) (x < y ? x : y)
@ -823,7 +824,7 @@ int IOCoordinator::_truncate(const bf::path &bfpath, size_t newSize, ScopedFileL
else
{
meta.updateEntryLength(objects[0].offset, newSize - objects[0].offset);
assert(objects[0].offset >= 0 && objectSize > (newSize - objects[0].offset));
assert(utils::is_nonnegative(objects[0].offset) && objectSize > (newSize - objects[0].offset));
}
for (uint i = 1; i < objects.size(); i++)
meta.removeEntry(objects[i].offset);

43
utils/common/checks.h Normal file
View File

@ -0,0 +1,43 @@
/* Copyright (C) 2020 MariaDB Corporation
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; version 2 of
the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA. */
#ifndef UTILS_COMMON_CHECKS_H
#define UTILS_COMMON_CHECKS_H
#include <type_traits>
namespace utils {
template <typename T>
typename std::enable_if<std::is_unsigned<T>::value, bool>::type is_nonnegative(T)
{ return true; };
template <typename T>
typename std::enable_if<std::is_signed<T>::value, bool>::type is_nonnegative(T v)
{ return v >= 0; };
template <typename T>
typename std::enable_if<std::is_unsigned<T>::value, bool>::type is_negative(T)
{ return false; };
template <typename T>
typename std::enable_if<std::is_signed<T>::value, bool>::type is_negative(T v)
{ return v < 0; };
} // namespace utils
#endif // UTILS_COMMON_CHECKS_H

View File

@ -43,6 +43,8 @@ using namespace logging;
using namespace dataconvert;
#include "collation.h"
#include "checks.h"
namespace
{
struct lconv* convData = localeconv();
@ -349,7 +351,7 @@ uint64_t Func_cast_unsigned::getUintVal(Row& row,
uint64_t value = d.value / pow(10.0, dscale);
int lefto = (d.value - value * pow(10.0, dscale)) / pow(10.0, dscale - 1);
if ( value >= 0 && lefto > 4 )
if ( utils::is_nonnegative(value) && lefto > 4 )
value++;
return value;

View File

@ -34,6 +34,8 @@ using namespace execplan;
#include "dataconvert.h"
using namespace dataconvert;
#include "checks.h"
namespace funcexp
{
@ -75,10 +77,10 @@ string Func_elt::getStrVal(rowgroup::Row& row,
number = d.value / pow(10.0, dscale);
int lefto = (d.value - number * pow(10.0, dscale)) / pow(10.0, dscale - 1);
if ( number >= 0 && lefto > 4 )
if ( utils::is_nonnegative(number) && lefto > 4 )
number++;
if ( number < 0 && lefto < -4 )
if ( utils::is_negative(number) && lefto < -4 )
number--;
break;
@ -102,7 +104,7 @@ string Func_elt::getStrVal(rowgroup::Row& row,
}
std::string ret;
stringValue(parm[number], row, isNull, ret);
stringValue(parm[number], row, isNull, ret);
return ret;
}

View File

@ -49,6 +49,7 @@ using namespace BRM;
#include "cacheutils.h"
using namespace idbdatafile;
#include "utils_utf8.h"
#include "checks.h"
namespace
{
@ -407,7 +408,7 @@ int Dctnry::closeDctnry(bool realClose)
}
m_hwm = (HWM)m_lastFbo;
idbassert(m_dctnryOID >= 0);
idbassert(utils::is_nonnegative(m_dctnryOID));
if (idbdatafile::IDBPolicy::useHdfs() && realClose)
{

View File

@ -51,6 +51,9 @@ using namespace BRM;
#include "cacheutils.h"
#include "IDBDataFile.h"
#include "IDBPolicy.h"
#include "checks.h"
namespace WriteEngine
{
//StopWatch timer;
@ -1839,7 +1842,7 @@ uint8_t WE_DMLCommandProc::processBatchInsertBinary(messageqcpp::ByteStream& bs,
{
bs >> val8;
if (val8 < 0 &&
if (utils::is_negative(val8) &&
val8 != static_cast<int8_t>(joblist::TINYINTEMPTYROW) &&
val8 != static_cast<int8_t>(joblist::TINYINTNULL))
{
@ -1853,7 +1856,7 @@ uint8_t WE_DMLCommandProc::processBatchInsertBinary(messageqcpp::ByteStream& bs,
{
bs >> val16;
if (val16 < 0 &&
if (utils::is_negative(val16) &&
val16 != static_cast<int16_t>(joblist::SMALLINTEMPTYROW) &&
val16 != static_cast<int16_t>(joblist::SMALLINTNULL))
{
@ -1867,9 +1870,9 @@ uint8_t WE_DMLCommandProc::processBatchInsertBinary(messageqcpp::ByteStream& bs,
{
bs >> val32;
if (val32 < 0 &&
val32 != static_cast<int>(joblist::INTEMPTYROW) &&
val32 != static_cast<int>(joblist::INTNULL))
if (utils::is_negative(val32) &&
val32 != joblist::INTEMPTYROW &&
val32 != joblist::INTNULL)
{
val32 = 0;
pushWarning = true;
@ -1881,9 +1884,9 @@ uint8_t WE_DMLCommandProc::processBatchInsertBinary(messageqcpp::ByteStream& bs,
{
bs >> val64;
if (val64 < 0 &&
val64 != static_cast<long long>(joblist::BIGINTEMPTYROW) &&
val64 != static_cast<long long>(joblist::BIGINTNULL))
if (utils::is_negative(val64) &&
val64 != joblist::BIGINTEMPTYROW &&
val64 != joblist::BIGINTNULL)
{
val64 = 0;
pushWarning = true;