# HG changeset patch # User David Barts # Date 1664682239 25200 # Node ID cbe4c797c9a681cb3438092ce20ffef1a5e49da6 # Parent 72619175004e1edea5a96691d27dcb2ddbd80f4b Fix bug in parsing --length diff -r 72619175004e -r cbe4c797c9a6 src/main/kotlin/name/blackcap/passman/CreateSubcommand.kt --- a/src/main/kotlin/name/blackcap/passman/CreateSubcommand.kt Sat Oct 01 09:57:23 2022 -0700 +++ b/src/main/kotlin/name/blackcap/passman/CreateSubcommand.kt Sat Oct 01 20:43:59 2022 -0700 @@ -38,8 +38,10 @@ val length = try { rawLength?.toInt() ?: DEFAULT_GENERATED_LENGTH } catch (e: NumberFormatException) { + -1 + } + if (length < MIN_GENERATED_LENGTH) { die("${see(rawLength)} - invalid length") - -1 /* will never happen */ } Entry.withGeneratedPassword(length, commandLine.hasOption(SYMBOLS), diff -r 72619175004e -r cbe4c797c9a6 src/main/kotlin/name/blackcap/passman/UpdateSubcommand.kt --- a/src/main/kotlin/name/blackcap/passman/UpdateSubcommand.kt Sat Oct 01 09:57:23 2022 -0700 +++ b/src/main/kotlin/name/blackcap/passman/UpdateSubcommand.kt Sat Oct 01 20:43:59 2022 -0700 @@ -57,14 +57,15 @@ db = Database.open() nameIn = commandLine.args[0] id = db.makeKey(nameIn) - length = commandLine.getOptionValue(LENGTH)?.let { rawLength -> - try { - rawLength.toInt() - } catch (e: NumberFormatException) { - die("${see(rawLength)} - invalid length") - -1 /* will never happen */ - } - } ?: DEFAULT_GENERATED_LENGTH + val rawLength = commandLine.getOptionValue(LENGTH) + length = try { + rawLength?.toInt() ?: DEFAULT_GENERATED_LENGTH + } catch (e: NumberFormatException) { + -1 + } + if (length < MIN_GENERATED_LENGTH) { + die("${see(rawLength)} - invalid length") + } } private fun checkArguments(): Unit {