← Back to context

Comment by clark_dent

3 hours ago

Could you humor a coding noob--how do you deal with utterly insane inputs like that?

Arbitrary precision arithmetic (GMP, BigInteger, etc). Numbers can take arbitrary amounts of memory, instead of just a single machine word.

Crash and report an error.

  • You report an error and exit cleanly with a proper operating system error code. Crashing is a quick hack, acceptable for throwaway projects but not in software used long-term.

    • Crashing (in the sense of "give up and exit with an error") on invalid inputs is valid (and often the best thing) in many cases.

      Fix your inputs.

      1 reply →

You first ask if you really need to.

  • Unless you're exposing it to the internet, ever, in the entire future history of the program. Then you kind of have to, in one form or another.

    • You have to, but you probably shouldn’t do it by trying to add the inputs. That opens a door for DDOS attacks.

      Returning an error on inputs that are too long (for some definition of it) is the way to go.