don't crash when upgrading collection with ntid of 0

This commit is contained in:
Damien Elmes 2020-08-23 14:14:44 +10:00
parent 2291f9a9fb
commit 134765036c

View File

@ -351,8 +351,13 @@ and ord in ",
pub(crate) fn upgrade_notetypes_to_schema15(&self) -> Result<()> { pub(crate) fn upgrade_notetypes_to_schema15(&self) -> Result<()> {
let nts = self.get_schema11_notetypes()?; let nts = self.get_schema11_notetypes()?;
let mut names = HashSet::new(); let mut names = HashSet::new();
for (ntid, nt) in nts { for (mut ntid, nt) in nts {
let mut nt = NoteType::from(nt); 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::<u32>().max(1) as i64;
nt.id = ntid;
}
nt.normalize_names(); nt.normalize_names();
nt.ensure_names_unique(); nt.ensure_names_unique();
loop { loop {