crankycyclops / trogdor-pp

A unified engine for building text adventures and MUDs with batteries included.
GNU General Public License v3.0
15 stars 2 forks source link

When validating integers, validate for overflow as well #82

Open crankycyclops opened 2 years ago

crankycyclops commented 2 years ago

When I validate integers, I should also validate for overflow (make sure the value represented in the string isn't larger than what can actually be stored in the data type.) That means I should have versions of this function that check for 32 as well as 64-bit integers, and both signed and unsigned for each.

crankycyclops commented 2 years ago

To check for overflow, I just need to do this:

    try {
        auto value = std::stoi("999999999999999999999999999");
    }
    catch (const std::out_of_range&) {
      ...
    }

Also, I need to write an isValidUnsigned* family of functions as well. When I do, revsisit my validation of SET_TIMER_PERIOD in instantiator.cpp.