removed cast of malloc result

This commit is contained in:
poum 2019-04-03 17:37:25 +02:00
parent bdda8a5c85
commit 265df8599d

View file

@ -158,7 +158,7 @@ static int ZDParseHeader(ZoneDetect *library)
uint32_t index = UINT32_C(7); uint32_t index = UINT32_C(7);
library->fieldNames = malloc(library->numFields * sizeof(char *)); library->fieldNames = malloc(library->numFields * sizeof *library->fieldNames);
for(size_t i = 0; i < library->numFields; i++) { for(size_t i = 0; i < library->numFields; i++) {
library->fieldNames[i] = ZDParseString(library, &index); library->fieldNames[i] = ZDParseString(library, &index);
} }
@ -385,7 +385,7 @@ void ZDCloseDatabase(ZoneDetect *library)
ZoneDetect *ZDOpenDatabase(const char *path) ZoneDetect *ZDOpenDatabase(const char *path)
{ {
ZoneDetect *const library = (ZoneDetect *)malloc(sizeof(*library)); ZoneDetect *const library = malloc(sizeof *library);
if(library) { if(library) {
memset(library, 0, sizeof(*library)); memset(library, 0, sizeof(*library));
@ -431,7 +431,7 @@ ZoneDetectResult *ZDLookup(const ZoneDetect *library, float lat, float lon, floa
uint32_t metadataIndex = 0; uint32_t metadataIndex = 0;
uint32_t polygonIndex = 0; uint32_t polygonIndex = 0;
ZoneDetectResult *results = malloc(sizeof(ZoneDetectResult)); ZoneDetectResult *results = malloc(sizeof *results);
if(!results) { if(!results) {
return NULL; return NULL;
} }
@ -462,7 +462,7 @@ ZoneDetectResult *ZDLookup(const ZoneDetect *library, float lat, float lon, floa
if(lookupResult == ZD_LOOKUP_PARSE_ERROR) { if(lookupResult == ZD_LOOKUP_PARSE_ERROR) {
break; break;
} else if(lookupResult != ZD_LOOKUP_NOT_IN_ZONE) { } else if(lookupResult != ZD_LOOKUP_NOT_IN_ZONE) {
ZoneDetectResult *const newResults = realloc(results, sizeof(ZoneDetectResult) * (numResults + 2)); ZoneDetectResult *const newResults = realloc(results, sizeof *newResults * (numResults + 2));
if(newResults) { if(newResults) {
results = newResults; results = newResults;
@ -527,7 +527,7 @@ ZoneDetectResult *ZDLookup(const ZoneDetect *library, float lat, float lon, floa
/* Lookup metadata */ /* Lookup metadata */
for(size_t i = 0; i < numResults; i++) { for(size_t i = 0; i < numResults; i++) {
uint32_t tmpIndex = library->metadataOffset + results[i].metaId; uint32_t tmpIndex = library->metadataOffset + results[i].metaId;
results[i].data = malloc(library->numFields * sizeof(char *)); results[i].data = malloc(library->numFields * sizeof *results[i].data);
if(results[i].data) { if(results[i].data) {
for(size_t j = 0; j < library->numFields; j++) { for(size_t j = 0; j < library->numFields; j++) {
results[i].data[j] = ZDParseString(library, &tmpIndex); results[i].data[j] = ZDParseString(library, &tmpIndex);