Ignore:
Timestamp:
05/31/18 03:23:05 (6 years ago)
Author:
Maciej Komosinski
Message:

Protected against overflow when converting floating point value to integer value

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpp/frams/util/extvalue.cpp

    r786 r794  
    945945        {
    946946        case TInt: return idata();
    947         case TDouble: return (int)ddata();
     947        case TDouble:
     948        {
     949                bool toobig = false;
     950                if (((toobig = (ddata() > (double)INT_MAX)))
     951                        || (ddata() < (double)INT_MIN))
     952                {
     953                        logPrintf("ExtValue", "getInt", LOG_ERROR, "Overflow when converting floating point value to integer; using %s allowed integer '%d' instead of '%s'", toobig ? "maximal" : "minimal", toobig ? INT_MAX : INT_MIN, getString().c_str());
     954                        return toobig ? INT_MAX : INT_MIN;
     955                }
     956                return (int)ddata();
     957        }
    948958        case TString: return getInt(sdata().c_str());
    949959        case TObj:
Note: See TracChangeset for help on using the changeset viewer.