From 134765036cdca2ab94a5316bfe2fdbf90464f428 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Sun, 23 Aug 2020 14:14:44 +1000 Subject: [PATCH] don't crash when upgrading collection with ntid of 0 --- rslib/src/storage/notetype/mod.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/rslib/src/storage/notetype/mod.rs b/rslib/src/storage/notetype/mod.rs index f52a03e3c43..951b8314c26 100644 --- a/rslib/src/storage/notetype/mod.rs +++ b/rslib/src/storage/notetype/mod.rs @@ -351,8 +351,13 @@ and ord in ", pub(crate) fn upgrade_notetypes_to_schema15(&self) -> Result<()> { let nts = self.get_schema11_notetypes()?; let mut names = HashSet::new(); - for (ntid, nt) in nts { + for (mut ntid, nt) in nts { let mut nt = NoteType::from(nt); + // note types with id 0 found in the wild; assign a random ID + if ntid.0 == 0 { + ntid.0 = rand::random::().max(1) as i64; + nt.id = ntid; + } nt.normalize_names(); nt.ensure_names_unique(); loop {