From 990a722852ab22b55db342f93ebe03e6ed122f7f Mon Sep 17 00:00:00 2001 From: mo8it Date: Mon, 14 Oct 2024 15:57:44 +0200 Subject: [PATCH] Limit the maximum number of exercises to 999 --- src/dev/check.rs | 5 +++++ src/term.rs | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/dev/check.rs b/src/dev/check.rs index 5a7aaed4..bd73ec8c 100644 --- a/src/dev/check.rs +++ b/src/dev/check.rs @@ -17,6 +17,7 @@ use crate::{ CURRENT_FORMAT_VERSION, }; +const MAX_N_EXERCISES: usize = 999; const MAX_EXERCISE_NAME_LEN: usize = 32; // Find a char that isn't allowed in the exercise's `name` or `dir`. @@ -347,6 +348,10 @@ fn check_solutions( pub fn check(require_solutions: bool) -> Result<()> { let info_file = InfoFile::parse()?; + if info_file.exercises.len() > MAX_N_EXERCISES { + bail!("The maximum number of exercises is {MAX_N_EXERCISES}"); + } + if cfg!(debug_assertions) { // A hack to make `cargo run -- dev check` work when developing Rustlings. check_cargo_toml(&info_file.exercises, "dev/Cargo.toml", b"../")?; diff --git a/src/term.rs b/src/term.rs index 86909f08..e3bfd7bb 100644 --- a/src/term.rs +++ b/src/term.rs @@ -166,7 +166,7 @@ pub fn progress_bar<'a>( total: u16, term_width: u16, ) -> io::Result<()> { - debug_assert!(total < 1000); + debug_assert!(total <= 999); debug_assert!(progress <= total); const PREFIX: &[u8] = b"Progress: [";