From 61d3cce4b813cb0661a7c8e4549c7d60ae73fcae Mon Sep 17 00:00:00 2001 From: PatR Date: Mon, 3 Jun 2024 09:28:38 -0700 Subject: [PATCH] fix static analyzer complaint in remove_room() Since croom and maxroom both point to elements in the rooms[] array, the complaint that the memcpy() in | if (croom != maxroom) | memcpy(croom, maxroom, sizeof (struct room)); might have overlapping source and destination is bogus. The fix is trivial but not vetted by the analyzer. --- src/mkmap.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/mkmap.c b/src/mkmap.c index 4e7c057c1..b007ec964 100644 --- a/src/mkmap.c +++ b/src/mkmap.c @@ -1,4 +1,4 @@ -/* NetHack 3.7 mkmap.c $NHDT-Date: 1596498181 2020/08/03 23:43:01 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.28 $ */ +/* NetHack 3.7 mkmap.c $NHDT-Date: 1717432093 2024/06/03 16:28:13 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.40 $ */ /* Copyright (c) J. C. Collet, M. Stephenson and D. Cohrs, 1992 */ /* NetHack may be freely redistributed. See license for details. */ @@ -403,9 +403,11 @@ remove_rooms(int lx, int ly, int hx, int hy) } /* - * Remove roomno from the rooms array, decrementing nroom. Also updates - * all level roomno values of affected higher numbered rooms. Assumes - * level structure contents corresponding to roomno have already been reset. + * Remove roomno from the rooms array, decrementing nroom. + * The last room is swapped from the being-removed room and locations + * within it have their roomno field updated. Other rooms are unaffected. + * Assumes level structure contents corresponding to roomno have already + * been reset. * Currently handles only the removal of rooms that have no subrooms. */ staticfn void @@ -420,8 +422,7 @@ remove_room(unsigned int roomno) /* since the order in the array only matters for making corridors, * copy the last room over the one being removed on the assumption * that corridors have already been dug. */ - (void) memcpy((genericptr_t) croom, (genericptr_t) maxroom, - sizeof(struct mkroom)); + *croom = *maxroom; /* since maxroom moved, update affected level roomno values */ oroomno = gn.nroom + ROOMOFFSET;