fix: findUse can return NULL crash

The main cause of the crash was the path for UNDO_CELL_PLACE this was
trigged by performing a number of cell create/move operations (unknown
exactly what sequence).  Then a large number of "undo" operations.

There is an ASSERT in findUse() but that does not seem built into the
release (or debug CFLAGS=-g3) builds.
This commit is contained in:
Darryl L. Miles 2024-06-04 15:14:30 +01:00 committed by Tim Edwards
parent 3638d382d6
commit e119188f23
1 changed files with 19 additions and 11 deletions

View File

@ -788,9 +788,11 @@ dbUndoCellBack(up)
break; break;
case UNDO_CELL_PLACE: case UNDO_CELL_PLACE:
use = findUse(up, TRUE); use = findUse(up, TRUE);
DBUnLinkCell(use, up->cue_parent); if(use) {
DBDeleteCell(use); DBUnLinkCell(use, up->cue_parent);
(void) DBCellDeleteUse(use); DBDeleteCell(use);
(void) DBCellDeleteUse(use);
}
DBReComputeBbox(up->cue_parent); DBReComputeBbox(up->cue_parent);
DBWAreaChanged(up->cue_parent, &up->cue_bbox, DBW_ALLWINDOWS, DBWAreaChanged(up->cue_parent, &up->cue_bbox, DBW_ALLWINDOWS,
(TileTypeBitMask *) NULL); (TileTypeBitMask *) NULL);
@ -804,9 +806,11 @@ dbUndoCellBack(up)
*/ */
case UNDO_CELL_CLRID: case UNDO_CELL_CLRID:
use = findUse(up, FALSE); /* Find it with a NULL id */ use = findUse(up, FALSE); /* Find it with a NULL id */
(void) DBReLinkCell(use, up->cue_id); if(use) {
DBWAreaChanged(up->cue_parent, &up->cue_bbox, (void) DBReLinkCell(use, up->cue_id);
(int) ~use->cu_expandMask, &DBAllButSpaceBits); DBWAreaChanged(up->cue_parent, &up->cue_bbox,
(int) ~use->cu_expandMask, &DBAllButSpaceBits);
}
break; break;
/* /*
* The following is a hack. * The following is a hack.
@ -817,16 +821,20 @@ dbUndoCellBack(up)
*/ */
case UNDO_CELL_SETID: case UNDO_CELL_SETID:
use = findUse(up, TRUE); /* Find it with current id */ use = findUse(up, TRUE); /* Find it with current id */
DBUnLinkCell(use, up->cue_parent); if(use) {
freeMagic(use->cu_id); DBUnLinkCell(use, up->cue_parent);
use->cu_id = (char *) NULL; freeMagic(use->cu_id);
use->cu_id = (char *) NULL;
}
break; break;
case UNDO_CELL_LOCKDOWN: case UNDO_CELL_LOCKDOWN:
use = findUse(up, TRUE); use = findUse(up, TRUE);
use->cu_flags = up->cue_flags; if(use) {
DBWAreaChanged(up->cue_parent, &up->cue_bbox, use->cu_flags = up->cue_flags;
DBWAreaChanged(up->cue_parent, &up->cue_bbox,
(int) ~use->cu_expandMask, &DBAllButSpaceBits); (int) ~use->cu_expandMask, &DBAllButSpaceBits);
}
break; break;
} }
} }