remove unnecessary null checks

This commit is contained in:
DarthArgus
2014-10-26 22:53:42 -07:00
parent eb2e7c78d8
commit 594b3a4254
56 changed files with 98 additions and 199 deletions
@@ -52,7 +52,7 @@ namespace DebugMonitorNamespace
DWORD type = 0;
DWORD size = sizeof(DWORD);
LONG result = RegQueryValueEx(registryKey, name, NULL, &type, reinterpret_cast<LPBYTE>(&value), &size);
if (result != ERROR_SUCCESS || type != REG_DWORD && size != sizeof(int))
if ((result != ERROR_SUCCESS || type != REG_DWORD) && (size != sizeof(int)))
value = defaultValue;
return value;
}
@@ -1612,9 +1612,9 @@ int MemoryManagerNamespace::quickGuessIsValidPointerFromHeap(void const * userPo
AllocatedBlock const * allocatedBlock = reinterpret_cast<AllocatedBlock const *>(reinterpret_cast<byte const *>(userPointer) - (cms_allocatedBlockSize + cms_guardBandSize));
ms_criticalSection->enter();
if (!result && allocatedBlock->getNext()->getPrevious() != allocatedBlock) result = 1;
if (!result && allocatedBlock->getPrevious()->getNext() != allocatedBlock) result = 2;
if (!result && allocatedBlock->isFree()) result = 3;
if (allocatedBlock->getNext()->getPrevious() != allocatedBlock) result = 1;
if (allocatedBlock->getPrevious()->getNext() != allocatedBlock) result = 2;
if (allocatedBlock->isFree()) result = 3;
ms_criticalSection->leave();
return result;
@@ -63,7 +63,6 @@ int property, value, itemCount;
UNREF(source);
MessageQueueCraftCustomization * msg = new MessageQueueCraftCustomization();
NOT_NULL(msg);
Archive::get(source, name);
msg->setName(name);
@@ -57,7 +57,6 @@ MessageQueue::Data* MessageQueueCraftExperiment::unpack(Archive::ReadIterator &
uint8 sequenceId;
Archive::get(source, sequenceId);
MessageQueueCraftExperiment* const msg = new MessageQueueCraftExperiment(sequenceId);
NOT_NULL(msg);
int count;
int attribute, points;
@@ -53,7 +53,6 @@ void MessageQueueCraftIngredients::pack(const MessageQueue::Data* const data, Ar
MessageQueue::Data* MessageQueueCraftIngredients::unpack(Archive::ReadIterator & source)
{
MessageQueueCraftIngredients* const msg = new MessageQueueCraftIngredients();
NOT_NULL(msg);
int count;
Unicode::String name;
@@ -61,7 +61,6 @@ void MessageQueueCreateSaga::pack(const MessageQueue::Data* const data, Archive:
MessageQueue::Data* MessageQueueCreateSaga::unpack(Archive::ReadIterator & source)
{
MessageQueueCreateSaga* const msg = new MessageQueueCreateSaga();
NOT_NULL(msg);
std::string questName;
std::string questDescription;
@@ -93,7 +93,6 @@ MessageQueue::Data* MessageQueueDraftSchematics::unpack(Archive::ReadIterator &
Archive::get(source, stationId);
MessageQueueDraftSchematics* const msg = new MessageQueueDraftSchematics(toolId, stationId);
NOT_NULL(msg);
int count, category;
uint32 serverCrc, sharedCrc;
@@ -71,7 +71,6 @@ MessageQueue::Data* MessageQueueDraftSlots::unpack(Archive::ReadIterator & sourc
Archive::get(source, canManufacture);
MessageQueueDraftSlots * const msg = new MessageQueueDraftSlots(toolId, manfSchemId);
NOT_NULL(msg);
msg->setPrototypeId(testProtoId);
msg->setVolume(volume);
@@ -83,7 +83,6 @@ MessageQueue::Data* MessageQueueDraftSlotsQueryResponse::unpack(Archive::ReadIte
Archive::get(source, canManufacture);
MessageQueueDraftSlotsQueryResponse * const msg = new MessageQueueDraftSlotsQueryResponse (crc);
NOT_NULL(msg);
msg->setComplexity(complexity);
msg->setVolume(volume);
msg->setCanManufacture(canManufacture);
@@ -44,7 +44,6 @@ void MessageQueueNpcConversationMessage::pack(const MessageQueue::Data* const da
MessageQueue::Data* MessageQueueNpcConversationMessage::unpack(Archive::ReadIterator & source)
{
MessageQueueNpcConversationMessage * msg = new MessageQueueNpcConversationMessage;
NOT_NULL(msg);
Unicode::String response;
Archive::get(source, response);
@@ -60,7 +60,6 @@ MessageQueue::Data* MessageQueueOpponentInfo::unpack(Archive::ReadIterator & sou
MessageQueueOpponentInfo * msg = new MessageQueueOpponentInfo();
msg->setOpponent(opponent);
msg->setAttributes(health, action, mind);
NOT_NULL(msg);
return msg;
}
@@ -76,7 +76,6 @@ MessageQueue::Data* MessageQueuePushCreature::unpack(Archive::ReadIterator & sou
Archive::get(source, distance);
MessageQueuePushCreature * const msg = new MessageQueuePushCreature(attacker, defender, attackerPos, defenderPos, distance);
NOT_NULL(msg);
return msg;
}
@@ -48,7 +48,6 @@ void MessageQueueStartNpcConversation::pack(const MessageQueue::Data* const data
MessageQueue::Data* MessageQueueStartNpcConversation::unpack(Archive::ReadIterator & source)
{
MessageQueueStartNpcConversation * msg = new MessageQueueStartNpcConversation;
NOT_NULL(msg);
NetworkId npc;
Archive::get(source, npc);
@@ -47,7 +47,6 @@ void MessageQueueStopNpcConversation::pack(const MessageQueue::Data* const data,
MessageQueue::Data* MessageQueueStopNpcConversation::unpack(Archive::ReadIterator & source)
{
MessageQueueStopNpcConversation * msg = new MessageQueueStopNpcConversation;
NOT_NULL(msg);
// npc
{
@@ -58,7 +58,6 @@ void MessageQueueStringList::pack(const MessageQueue::Data* const data, Archive:
MessageQueue::Data* MessageQueueStringList::unpack(Archive::ReadIterator & source)
{
MessageQueueStringList * msg = new MessageQueueStringList;
NOT_NULL(msg);
uint8 count;
Unicode::String string;
@@ -72,7 +72,6 @@ MessageQueue::Data* MessageQueueUpdateShipOnCollision::unpack(Archive::ReadItera
Archive::get(source, clampedStrengthOfImpact);
MessageQueueUpdateShipOnCollision * const msg = new MessageQueueUpdateShipOnCollision(deltaToMove, newVelocity, clampedStrengthOfImpact);
NOT_NULL(msg);
return msg;
}
@@ -259,7 +259,6 @@ void StructureFootprint::load_0000 (Iff& iff)
//-- allocate footprint
IS_NULL (m_data);
m_data = new LotType [static_cast<size_t> (m_width * m_height)];
NOT_NULL (m_data);
//-- convert string to footprint
const char* const buffer = footprint.c_str ();
@@ -53,7 +53,6 @@ void Portal::install()
{
delete ms_doorStyleTable;
ms_doorStyleTable = new DataTable();
NOT_NULL(ms_doorStyleTable);
ms_doorStyleTable->load(dataTableIff);
}
@@ -1918,7 +1918,6 @@ std::string name;
// now parse the objvar data
line = paramStart;
CompilerDynamicVariableParamData *newData = new CompilerDynamicVariableParamData(name, type);
NOT_NULL(newData);
switch (type)
{
case DynamicVariableParamData::INTEGER:
@@ -2431,7 +2430,6 @@ const char *parseWeightedList(
TpfFile &file, Q & param, const char *line)
{
LIST *list = new LIST;
NOT_NULL(list);
param.setValue(list);
int totalWeight = 0;
for (;;)
@@ -2439,7 +2437,6 @@ const char *parseWeightedList(
VALUE value;
Q *valueParam = NULL;
value.value = valueParam = new Q;
NOT_NULL(valueParam);
list->push_back(value);
VALUE *newValue = &list->back();
// test to see if we need to go to the next line
@@ -614,7 +614,6 @@ int DataTable::searchColumnString( int column, const std::string & searchValue )
if (!voidIndex)
{
std::pair<std::multimap<const std::string, int>, std::multimap<int, int> > * indexPair = new std::pair<std::multimap<const std::string, int>, std::multimap<int, int> >;
NOT_NULL(indexPair);
m_index[static_cast<size_t>(column)] = static_cast<void *>(indexPair);
@@ -653,7 +652,6 @@ int DataTable::searchColumnFloat( int column, float searchValue ) const
if (!voidIndex)
{
std::multimap<float, int> * index = new std::multimap<float, int>;
NOT_NULL(index);
m_index[static_cast<size_t>(column)] = static_cast<void *>(index);
@@ -692,7 +690,6 @@ int DataTable::searchColumnInt( int column, int searchValue ) const
if (columnType == DataTableColumnType::DT_Int)
{
std::multimap<int, int> * index = new std::multimap<int, int>;
NOT_NULL(index);
m_index[static_cast<size_t>(column)] = static_cast<void *>(index);
@@ -709,7 +706,6 @@ int DataTable::searchColumnInt( int column, int searchValue ) const
else if (columnType == DataTableColumnType::DT_String)
{
std::pair<std::multimap<const std::string, int>, std::multimap<int, int> > * indexPair = new std::pair<std::multimap<const std::string, int>, std::multimap<int, int> >;
NOT_NULL(indexPair);
m_index[static_cast<size_t>(column)] = static_cast<void *>(indexPair);
@@ -543,7 +543,6 @@ void DataTableWriter::_loadFromSpreadsheetTab(const char * filename)
int bufferLength = fileLength + 1;
char* buffer = new char[bufferLength];
memset(buffer, 0, bufferLength);
NOT_NULL(buffer);
int bytes_read = inputFile.read(buffer, fileLength);
FATAL(!bytes_read, ("Didn't read in any bytes when loading %s.", filename));
@@ -998,7 +998,6 @@ void DynamicVariableParamData::loadFromIff(Iff &file)
for (int i = 0; i < count; ++i)
{
DynamicVariableParamData *newData = new DynamicVariableParamData;
NOT_NULL(newData);
newData->loadFromIff(file);
m_data.lparam->push_back(newData);
}
@@ -99,11 +99,10 @@ XmlTreeDocument* XmlTreeDocument::createDocument(const char * rootNodeName)
XmlTreeDocument *treeDoc = new XmlTreeDocument(doc);
DEBUG_WARNING( !treeDoc, ("Attempted to make new XmlTreeDoc but failed") );
if (!treeDoc)
{
xmlFree(doc);
return 0;
}
xmlFree(doc);
return 0;
treeDoc->fetch();
return treeDoc;
}
@@ -120,12 +119,11 @@ XmlTreeDocument * XmlTreeDocument::buildDocumentFromText(const std::string &inpu
return 0;
}
XmlTreeDocument *treeDoc = new XmlTreeDocument(doc);
if(!treeDoc)
{
DEBUG_FATAL(true, ("Failure building XmlTreeDocument after successful parsing of memory buffer."));
xmlFree(doc);
return 0;
}
DEBUG_FATAL(true, ("Failure building XmlTreeDocument after successful parsing of memory buffer."));
xmlFree(doc);
return 0;
treeDoc->fetch();
return treeDoc;
}