Repair next_id and reject duplicate ids on load (#1050)
Loading a design raises next_id above the largest feature, component and occurrence id, so a missing or stale value can't hand a new item an id already in use, and duplicate ids are rejected as a damaged design. Id allocation uses checked_add, so an exhausted id space is an error instead of a wrap or a panic. Part of #1016 (points 1, 2 and 4). nekomario28's #1061 reached the same fix independently; thanks to both. Co-authored-by: nekomario28 <[email protected]>
This commit is contained in:
1 parent
dde6d48dd0
commit
1ac8bf4aa8
3 files changed
+79
-3
No files matched your search
@@ -2041,7 +2041,7 @@ impl Document {
|
||||
return Err(DocError::Invalid("too many components".into()));
|
||||
}
|
||||
let id = self.next_id.max(1);
|
||||
self.next_id = id + 1;
|
||||
self.next_id = id.checked_add(1).ok_or_else(|| DocError::Invalid("too many items in the design".into()))?;
|
||||
let name = match name.map(str::trim) {
|
||||
Some(n) if !n.is_empty() => n.to_string(),
|
||||
_ => {
|
||||
@@ -2153,7 +2153,7 @@ impl Document {
|
||||
0
|
||||
};
|
||||
let id = self.next_id.max(1);
|
||||
self.next_id = id + 1;
|
||||
self.next_id = id.checked_add(1).ok_or_else(|| DocError::Invalid("too many items in the design".into()))?;
|
||||
let name = match name {
|
||||
Some(n) if !n.trim().is_empty() => n.trim().to_string(),
|
||||
_ => self.unique_name(kind.base_name()),
|
||||
|
||||
Reference in new issue
Block a user