diff --git a/Data Miners/XRGTemperatureMiner.m b/Data Miners/XRGTemperatureMiner.m index 3a2d02e..290c4b2 100644 --- a/Data Miners/XRGTemperatureMiner.m +++ b/Data Miners/XRGTemperatureMiner.m @@ -210,14 +210,17 @@ - (NSString *)unitsForLocation:(NSString *)location { - (void)regenerateLocationKeyOrder { NSArray *locations = [sensorData allKeys]; NSInteger numLocations = [locations count]; - bool *alreadyUsed = calloc(numLocations, sizeof(bool)); - int i; + if (numLocations == 0) return; + + BOOL alreadyUsed[numLocations]; [locationKeysInOrder removeAllObjects]; - for (i = 0; i < numLocations; i++) { + for (int i = 0; i < numLocations; i++) { if (locations[i] == nil) { alreadyUsed[i] = YES; + } else { + alreadyUsed[i] = NO; } } @@ -239,7 +242,7 @@ - (void)regenerateLocationKeyOrder { NSMutableArray *tmpDrive = [NSMutableArray arrayWithCapacity:3]; NSMutableArray *tmpOthers = [NSMutableArray arrayWithCapacity:3]; - for (i = 0; i < numLocations; i++) { + for (int i = 0; i < numLocations; i++) { if (alreadyUsed[i]) continue; NSString *location = locations[i]; @@ -331,8 +334,8 @@ - (void)regenerateLocationKeyOrder { } // Loop through and add any left overs - for (i = 0; i < numLocations; i++) { - if (!alreadyUsed[i] & [sensorData[locations[i]][GSUnitsKey] isEqualToString:types[typeIndex]]) { + for (int i = 0; i < numLocations; i++) { + if ((!alreadyUsed[i]) & [sensorData[locations[i]][GSUnitsKey] isEqualToString:types[typeIndex]]) { [tmpOthers addObject:locations[i]]; alreadyUsed[i] = YES; } @@ -354,8 +357,6 @@ - (void)regenerateLocationKeyOrder { [locationKeysInOrder addObjectsFromArray:[tmpDrive sortedArrayUsingDescriptors:@[descriptor]]]; [locationKeysInOrder addObjectsFromArray:[tmpOthers sortedArrayUsingDescriptors:@[descriptor]]]; } - - free(alreadyUsed); } - (float)currentValueForKey:(NSString *)locationKey {