Skip to content

Commit

Permalink
remove remaining NULL pointers by nullptrs
Browse files Browse the repository at this point in the history
  • Loading branch information
DennisOSRM committed Jun 24, 2014
1 parent 0c59ecf commit de7c56c
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 44 deletions.
19 changes: 5 additions & 14 deletions Algorithms/StronglyConnectedComponents.h
Expand Up @@ -214,20 +214,20 @@ class TarjanSCC
const char *pszDriverName = "ESRI Shapefile"; const char *pszDriverName = "ESRI Shapefile";
OGRSFDriver *poDriver = OGRSFDriver *poDriver =
OGRSFDriverRegistrar::GetRegistrar()->GetDriverByName(pszDriverName); OGRSFDriverRegistrar::GetRegistrar()->GetDriverByName(pszDriverName);
if (NULL == poDriver) if (nullptr == poDriver)
{ {
throw OSRMException("ESRI Shapefile driver not available"); throw OSRMException("ESRI Shapefile driver not available");
} }
OGRDataSource *poDS = poDriver->CreateDataSource("component.shp", NULL); OGRDataSource *poDS = poDriver->CreateDataSource("component.shp", nullptr);


if (NULL == poDS) if (nullptr == poDS)
{ {
throw OSRMException("Creation of output file failed"); throw OSRMException("Creation of output file failed");
} }


OGRLayer *poLayer = poDS->CreateLayer("component", NULL, wkbLineString, NULL); OGRLayer *poLayer = poDS->CreateLayer("component", nullptr, wkbLineString, nullptr);


if (NULL == poLayer) if (nullptr == poLayer)
{ {
throw OSRMException("Layer creation failed."); throw OSRMException("Layer creation failed.");
} }
Expand Down Expand Up @@ -325,15 +325,6 @@ class TarjanSCC
SimpleLogger().Write() << "identified: " << component_size_vector.size() SimpleLogger().Write() << "identified: " << component_size_vector.size()
<< " many components, marking small components"; << " many components, marking small components";


// TODO/C++11: prime candidate for lambda function
// unsigned size_one_counter = 0;
// for (unsigned i = 0, end = component_size_vector.size(); i < end; ++i)
// {
// if (1 == component_size_vector[i])
// {
// ++size_one_counter;
// }
// }
unsigned size_one_counter = std::count_if(component_size_vector.begin(), unsigned size_one_counter = std::count_if(component_size_vector.begin(),
component_size_vector.end(), component_size_vector.end(),
[] (unsigned value) { return 1 == value;}); [] (unsigned value) { return 1 == value;});
Expand Down
6 changes: 3 additions & 3 deletions Contractor/Contractor.h
Expand Up @@ -731,7 +731,7 @@ class Contractor


template <bool RUNSIMULATION> template <bool RUNSIMULATION>
inline bool inline bool
ContractNode(ContractorThreadData *data, NodeID node, ContractionStats *stats = NULL) ContractNode(ContractorThreadData *data, NodeID node, ContractionStats *stats = nullptr)
{ {
ContractorHeap &heap = data->heap; ContractorHeap &heap = data->heap;
int inserted_edges_size = data->inserted_edges.size(); int inserted_edges_size = data->inserted_edges.size();
Expand All @@ -743,7 +743,7 @@ class Contractor
const NodeID source = contractor_graph->GetTarget(in_edge); const NodeID source = contractor_graph->GetTarget(in_edge);
if (RUNSIMULATION) if (RUNSIMULATION)
{ {
BOOST_ASSERT(stats != NULL); BOOST_ASSERT(stats != nullptr);
++stats->edges_deleted_count; ++stats->edges_deleted_count;
stats->original_edges_deleted_count += in_data.originalEdges; stats->original_edges_deleted_count += in_data.originalEdges;
} }
Expand Down Expand Up @@ -796,7 +796,7 @@ class Contractor
{ {
if (RUNSIMULATION) if (RUNSIMULATION)
{ {
BOOST_ASSERT(stats != NULL); BOOST_ASSERT(stats != nullptr);
stats->edges_added_count += 2; stats->edges_added_count += 2;
stats->original_edges_added_count += stats->original_edges_added_count +=
2 * (out_data.originalEdges + in_data.originalEdges); 2 * (out_data.originalEdges + in_data.originalEdges);
Expand Down
12 changes: 6 additions & 6 deletions DataStructures/InputReaderFactory.h
Expand Up @@ -44,8 +44,8 @@ struct BZ2Context


int readFromBz2Stream(void *pointer, char *buffer, int len) int readFromBz2Stream(void *pointer, char *buffer, int len)
{ {
void *unusedTmpVoid = NULL; void *unusedTmpVoid = nullptr;
char *unusedTmp = NULL; char *unusedTmp = nullptr;
BZ2Context *context = (BZ2Context *)pointer; BZ2Context *context = (BZ2Context *)pointer;
int read = 0; int read = 0;
while (0 == read && while (0 == read &&
Expand Down Expand Up @@ -76,7 +76,7 @@ int readFromBz2Stream(void *pointer, char *buffer, int len)
{ {
context->bz2 = BZ2_bzReadOpen( context->bz2 = BZ2_bzReadOpen(
&context->error, context->file, 0, 0, context->unused, context->nUnused); &context->error, context->file, 0, 0, context->unused, context->nUnused);
BOOST_ASSERT_MSG(NULL != context->bz2, "Could not open file"); BOOST_ASSERT_MSG(nullptr != context->bz2, "Could not open file");
} }
} }
else else
Expand Down Expand Up @@ -107,12 +107,12 @@ xmlTextReaderPtr inputReaderFactory(const char *name)
int error; int error;
context->bz2 = context->bz2 =
BZ2_bzReadOpen(&error, context->file, 0, 0, context->unused, context->nUnused); BZ2_bzReadOpen(&error, context->file, 0, 0, context->unused, context->nUnused);
if (context->bz2 == NULL || context->file == NULL) if (context->bz2 == nullptr || context->file == nullptr)
{ {
delete context; delete context;
return NULL; return nullptr;
} }
return xmlReaderForIO(readFromBz2Stream, closeBz2Stream, (void *)context, NULL, NULL, 0); return xmlReaderForIO(readFromBz2Stream, closeBz2Stream, (void *)context, nullptr, nullptr, 0);
} }
else else
{ {
Expand Down
42 changes: 21 additions & 21 deletions Extractor/XMLParser.cpp
Expand Up @@ -62,7 +62,7 @@ bool XMLParser::Parse()
} }


xmlChar *currentName = xmlTextReaderName(inputReader); xmlChar *currentName = xmlTextReaderName(inputReader);
if (currentName == NULL) if (currentName == nullptr)
{ {
continue; continue;
} }
Expand Down Expand Up @@ -115,7 +115,7 @@ InputRestrictionContainer XMLParser::ReadXMLRestriction()
} }
const int child_depth = xmlTextReaderDepth(inputReader); const int child_depth = xmlTextReaderDepth(inputReader);
xmlChar *child_name = xmlTextReaderName(inputReader); xmlChar *child_name = xmlTextReaderName(inputReader);
if (child_name == NULL) if (child_name == nullptr)
{ {
continue; continue;
} }
Expand All @@ -135,7 +135,7 @@ InputRestrictionContainer XMLParser::ReadXMLRestriction()
{ {
xmlChar *key = xmlTextReaderGetAttribute(inputReader, (const xmlChar *)"k"); xmlChar *key = xmlTextReaderGetAttribute(inputReader, (const xmlChar *)"k");
xmlChar *value = xmlTextReaderGetAttribute(inputReader, (const xmlChar *)"v"); xmlChar *value = xmlTextReaderGetAttribute(inputReader, (const xmlChar *)"v");
if (key != NULL && value != NULL) if (key != nullptr && value != nullptr)
{ {
if (xmlStrEqual(key, (const xmlChar *)"restriction") && if (xmlStrEqual(key, (const xmlChar *)"restriction") &&
StringStartsWith((const char *)value, "only_")) StringStartsWith((const char *)value, "only_"))
Expand All @@ -148,19 +148,19 @@ InputRestrictionContainer XMLParser::ReadXMLRestriction()
} }
} }


if (key != NULL) if (key != nullptr)
{ {
xmlFree(key); xmlFree(key);
} }
if (value != NULL) if (value != nullptr)
{ {
xmlFree(value); xmlFree(value);
} }
} }
else if (xmlStrEqual(child_name, (const xmlChar *)"member") == 1) else if (xmlStrEqual(child_name, (const xmlChar *)"member") == 1)
{ {
xmlChar *ref = xmlTextReaderGetAttribute(inputReader, (const xmlChar *)"ref"); xmlChar *ref = xmlTextReaderGetAttribute(inputReader, (const xmlChar *)"ref");
if (ref != NULL) if (ref != nullptr)
{ {
xmlChar *role = xmlTextReaderGetAttribute(inputReader, (const xmlChar *)"role"); xmlChar *role = xmlTextReaderGetAttribute(inputReader, (const xmlChar *)"role");
xmlChar *type = xmlTextReaderGetAttribute(inputReader, (const xmlChar *)"type"); xmlChar *type = xmlTextReaderGetAttribute(inputReader, (const xmlChar *)"type");
Expand All @@ -181,15 +181,15 @@ InputRestrictionContainer XMLParser::ReadXMLRestriction()
restriction.restriction.viaNode = StringToUint((const char *)ref); restriction.restriction.viaNode = StringToUint((const char *)ref);
} }


if (NULL != type) if (nullptr != type)
{ {
xmlFree(type); xmlFree(type);
} }
if (NULL != role) if (nullptr != role)
{ {
xmlFree(role); xmlFree(role);
} }
if (NULL != ref) if (nullptr != ref)
{ {
xmlFree(ref); xmlFree(ref);
} }
Expand Down Expand Up @@ -222,7 +222,7 @@ ExtractionWay XMLParser::ReadXMLWay()
} }
const int child_depth = xmlTextReaderDepth(inputReader); const int child_depth = xmlTextReaderDepth(inputReader);
xmlChar *child_name = xmlTextReaderName(inputReader); xmlChar *child_name = xmlTextReaderName(inputReader);
if (child_name == NULL) if (child_name == nullptr)
{ {
continue; continue;
} }
Expand All @@ -247,23 +247,23 @@ ExtractionWay XMLParser::ReadXMLWay()
xmlChar *key = xmlTextReaderGetAttribute(inputReader, (const xmlChar *)"k"); xmlChar *key = xmlTextReaderGetAttribute(inputReader, (const xmlChar *)"k");
xmlChar *value = xmlTextReaderGetAttribute(inputReader, (const xmlChar *)"v"); xmlChar *value = xmlTextReaderGetAttribute(inputReader, (const xmlChar *)"v");


if (key != NULL && value != NULL) if (key != nullptr && value != nullptr)
{ {
way.keyVals.Add(std::string((char *)key), std::string((char *)value)); way.keyVals.Add(std::string((char *)key), std::string((char *)value));
} }
if (key != NULL) if (key != nullptr)
{ {
xmlFree(key); xmlFree(key);
} }
if (value != NULL) if (value != nullptr)
{ {
xmlFree(value); xmlFree(value);
} }
} }
else if (xmlStrEqual(child_name, (const xmlChar *)"nd") == 1) else if (xmlStrEqual(child_name, (const xmlChar *)"nd") == 1)
{ {
xmlChar *ref = xmlTextReaderGetAttribute(inputReader, (const xmlChar *)"ref"); xmlChar *ref = xmlTextReaderGetAttribute(inputReader, (const xmlChar *)"ref");
if (ref != NULL) if (ref != nullptr)
{ {
way.path.push_back(StringToUint((const char *)ref)); way.path.push_back(StringToUint((const char *)ref));
xmlFree(ref); xmlFree(ref);
Expand All @@ -279,19 +279,19 @@ ImportNode XMLParser::ReadXMLNode()
ImportNode node; ImportNode node;


xmlChar *attribute = xmlTextReaderGetAttribute(inputReader, (const xmlChar *)"lat"); xmlChar *attribute = xmlTextReaderGetAttribute(inputReader, (const xmlChar *)"lat");
if (attribute != NULL) if (attribute != nullptr)
{ {
node.lat = static_cast<int>(COORDINATE_PRECISION * StringToDouble((const char *)attribute)); node.lat = static_cast<int>(COORDINATE_PRECISION * StringToDouble((const char *)attribute));
xmlFree(attribute); xmlFree(attribute);
} }
attribute = xmlTextReaderGetAttribute(inputReader, (const xmlChar *)"lon"); attribute = xmlTextReaderGetAttribute(inputReader, (const xmlChar *)"lon");
if (attribute != NULL) if (attribute != nullptr)
{ {
node.lon = static_cast<int>(COORDINATE_PRECISION * StringToDouble((const char *)attribute)); node.lon = static_cast<int>(COORDINATE_PRECISION * StringToDouble((const char *)attribute));
xmlFree(attribute); xmlFree(attribute);
} }
attribute = xmlTextReaderGetAttribute(inputReader, (const xmlChar *)"id"); attribute = xmlTextReaderGetAttribute(inputReader, (const xmlChar *)"id");
if (attribute != NULL) if (attribute != nullptr)
{ {
node.node_id = StringToUint((const char *)attribute); node.node_id = StringToUint((const char *)attribute);
xmlFree(attribute); xmlFree(attribute);
Expand All @@ -312,7 +312,7 @@ ImportNode XMLParser::ReadXMLNode()
} }
const int child_depth = xmlTextReaderDepth(inputReader); const int child_depth = xmlTextReaderDepth(inputReader);
xmlChar *child_name = xmlTextReaderName(inputReader); xmlChar *child_name = xmlTextReaderName(inputReader);
if (child_name == NULL) if (child_name == nullptr)
{ {
continue; continue;
} }
Expand All @@ -333,15 +333,15 @@ ImportNode XMLParser::ReadXMLNode()
{ {
xmlChar *key = xmlTextReaderGetAttribute(inputReader, (const xmlChar *)"k"); xmlChar *key = xmlTextReaderGetAttribute(inputReader, (const xmlChar *)"k");
xmlChar *value = xmlTextReaderGetAttribute(inputReader, (const xmlChar *)"v"); xmlChar *value = xmlTextReaderGetAttribute(inputReader, (const xmlChar *)"v");
if (key != NULL && value != NULL) if (key != nullptr && value != nullptr)
{ {
node.keyVals.Add(std::string((char *)(key)), std::string((char *)(value))); node.keyVals.Add(std::string((char *)(key)), std::string((char *)(value)));
} }
if (key != NULL) if (key != nullptr)
{ {
xmlFree(key); xmlFree(key);
} }
if (value != NULL) if (value != nullptr)
{ {
xmlFree(value); xmlFree(value);
} }
Expand Down

0 comments on commit de7c56c

Please sign in to comment.