diff options
author | Juan Carlos <juancarlospaco@gmail.com> | 2023-08-25 17:55:17 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-25 22:55:17 +0200 |
commit | a108a451c5c4be7158283c08a89691d9684dc578 (patch) | |
tree | 53188ea18e8d375eeebfcc9c90ba02c466288216 /compiler | |
parent | 1cc4d3f6220c5609e38258bd2c5a348e83106be4 (diff) | |
download | Nim-a108a451c5c4be7158283c08a89691d9684dc578.tar.gz |
Improve compiler cli args (#22509)
* . * Fix cli args out of range with descriptive error instead of crash * https://github.com/nim-lang/Nim/pull/22509#issuecomment-1692259451
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/commands.nim | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/compiler/commands.nim b/compiler/commands.nim index 6d162fab2..ba996f77e 100644 --- a/compiler/commands.nim +++ b/compiler/commands.nim @@ -891,15 +891,19 @@ proc processSwitch*(switch, arg: string, pass: TCmdLinePass, info: TLineInfo; defineSymbol(conf.symbols, "nodejs") of "maxloopiterationsvm": expectArg(conf, switch, arg, pass, info) - conf.maxLoopIterationsVM = parseInt(arg) + var value: int = 10_000_000 + discard parseSaturatedNatural(arg, value) + if not value > 0: localError(conf, info, "maxLoopIterationsVM must be a positive integer greater than zero") + conf.maxLoopIterationsVM = value of "errormax": expectArg(conf, switch, arg, pass, info) # Note: `nim check` (etc) can overwrite this. # `0` is meaningless, give it a useful meaning as in clang's -ferror-limit # If user doesn't set this flag and the code doesn't either, it'd # have the same effect as errorMax = 1 - let ret = parseInt(arg) - conf.errorMax = if ret == 0: high(int) else: ret + var value: int = 0 + discard parseSaturatedNatural(arg, value) + conf.errorMax = if value == 0: high(int) else: value of "verbosity": expectArg(conf, switch, arg, pass, info) let verbosity = parseInt(arg) @@ -913,7 +917,9 @@ proc processSwitch*(switch, arg: string, pass: TCmdLinePass, info: TLineInfo; conf.mainPackageNotes = conf.notes of "parallelbuild": expectArg(conf, switch, arg, pass, info) - conf.numberOfProcessors = parseInt(arg) + var value: int = 0 + discard parseSaturatedNatural(arg, value) + conf.numberOfProcessors = value of "version", "v": expectNoArg(conf, switch, arg, pass, info) writeVersionInfo(conf, pass) |