crankycyclops / trogdor-pp

A unified engine for building text adventures and MUDs with batteries included.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

When validating integers, validate for overflow as well

crankycyclops opened this issue · comments

commented

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.

commented

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.