From 39f6489ac50d17159745bb51ceb08f729784ed26 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 15 Dec 2018 20:40:17 +0100 Subject: [PATCH] - two more places where explicit allocations could be replaced. --- src/p_things.cpp | 7 +++---- src/p_user.cpp | 8 ++------ 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/src/p_things.cpp b/src/p_things.cpp index f6d5139f6..0eb7ef5eb 100644 --- a/src/p_things.cpp +++ b/src/p_things.cpp @@ -572,23 +572,22 @@ static int SpawnableSort(const void *a, const void *b) static void DumpClassMap(FClassMap &themap) { FClassMap::Iterator it(themap); - FClassMap::Pair *pair, **allpairs; + FClassMap::Pair *pair; + TArray allpairs(themap.CountUsed(), true); int i = 0; // Sort into numerical order, since their arrangement in the map can // be in an unspecified order. - allpairs = new FClassMap::Pair *[themap.CountUsed()]; while (it.NextPair(pair)) { allpairs[i++] = pair; } - qsort(allpairs, i, sizeof(*allpairs), SpawnableSort); + qsort(allpairs.Data, i, sizeof(allpairs[0]), SpawnableSort); for (int j = 0; j < i; ++j) { pair = allpairs[j]; Printf ("%d %s\n", pair->Key, pair->Value->TypeName.GetChars()); } - delete[] allpairs; } CCMD(dumpspawnables) diff --git a/src/p_user.cpp b/src/p_user.cpp index 4bae6ee5e..6077d597c 100644 --- a/src/p_user.cpp +++ b/src/p_user.cpp @@ -429,12 +429,8 @@ void player_t::SetLogNumber (int num) } else { - int length=Wads.LumpLength(lumpnum); - char *data= new char[length+1]; - Wads.ReadLump (lumpnum, data); - data[length]=0; - SetLogText (data); - delete[] data; + auto lump = Wads.ReadLump(lumpnum); + SetLogText (lump.GetString()); } }