1
0
Fork 0

try to satisfy scan-build

This commit is contained in:
Jan Steemann 2015-04-16 15:04:11 +02:00
parent ad132ed202
commit e2000f571f
5 changed files with 79 additions and 168 deletions

View File

@ -3131,7 +3131,6 @@ int triagens::aql::interchangeAdjacentEnumerationsRule (Optimizer* opt,
if (! starts.empty()) { if (! starts.empty()) {
nextPermutationTuple(permTuple, starts); // will never return false nextPermutationTuple(permTuple, starts); // will never return false
bool ok = true;
do { do {
// Clone the plan: // Clone the plan:
@ -3173,7 +3172,6 @@ int triagens::aql::interchangeAdjacentEnumerationsRule (Optimizer* opt,
// OK, the new plan is ready, let's report it: // OK, the new plan is ready, let's report it:
if (! opt->addPlan(newPlan, rule->level, true)) { if (! opt->addPlan(newPlan, rule->level, true)) {
// have enough plans. stop permutations // have enough plans. stop permutations
ok = false;
break; break;
} }
} }
@ -3183,7 +3181,7 @@ int triagens::aql::interchangeAdjacentEnumerationsRule (Optimizer* opt,
} }
} }
while (ok && nextPermutationTuple(permTuple, starts)); while (nextPermutationTuple(permTuple, starts));
} }
return TRI_ERROR_NO_ERROR; return TRI_ERROR_NO_ERROR;

View File

@ -60,11 +60,15 @@ static void FreeSlot (TRI_fulltext_handle_slot_t* slot) {
static bool AllocateSlot (TRI_fulltext_handles_t* const handles, static bool AllocateSlot (TRI_fulltext_handles_t* const handles,
const uint32_t slotNumber) { const uint32_t slotNumber) {
if (handles == nullptr) {
return false;
}
if (handles->_slots[slotNumber] != nullptr) { if (handles->_slots[slotNumber] != nullptr) {
return true; return true;
} }
TRI_fulltext_handle_slot_t* slot = static_cast<TRI_fulltext_handle_slot_t*>(TRI_Allocate(TRI_UNKNOWN_MEM_ZONE, sizeof(TRI_fulltext_handle_slot_t), false)); auto slot = static_cast<TRI_fulltext_handle_slot_t*>(TRI_Allocate(TRI_UNKNOWN_MEM_ZONE, sizeof(TRI_fulltext_handle_slot_t), false));
if (slot == nullptr) { if (slot == nullptr) {
return false; return false;

View File

@ -1687,7 +1687,7 @@ static TRI_doc_collection_info_t* GetFigures (TRI_vocbase_col_t* collection) {
TRI_document_collection_t* document = collection->_collection; TRI_document_collection_t* document = collection->_collection;
TRI_doc_collection_info_t* info = document->figures(document); TRI_doc_collection_info_t* info = document->figures(document);
res = trx.finish(res); trx.finish(res);
// READ-LOCK end // READ-LOCK end
return info; return info;

View File

@ -607,20 +607,10 @@ static void JS_Debug (const v8::FunctionCallbackInfo<v8::Value>& args) {
if (console != nullptr) { if (console != nullptr) {
MUTEX_LOCKER(triagens::arango::serverConsoleMutex); MUTEX_LOCKER(triagens::arango::serverConsoleMutex);
if (serverConsole.load() != nullptr) { if (serverConsole.load() != nullptr) {
// Check again if console was withdrawn while (true) {
bool userAborted = false;
while (! userAborted) {
char* input = console->prompt("debug> "); char* input = console->prompt("debug> ");
if (userAborted) {
if (input != nullptr) {
TRI_FreeString(TRI_UNKNOWN_MEM_ZONE, input);
}
break;
}
if (input == nullptr) { if (input == nullptr) {
userAborted = true;
break; break;
} }

View File

@ -463,31 +463,19 @@ static bool FillShapeValueList (TRI_shaper_t* shaper,
TRI_json_t const* json, TRI_json_t const* json,
size_t level, size_t level,
bool create) { bool create) {
size_t i, n;
uint64_t total;
TRI_shape_value_t* values;
TRI_shape_value_t* p;
TRI_shape_value_t* e;
bool hs;
bool hl;
TRI_shape_sid_t s; TRI_shape_sid_t s;
TRI_shape_sid_t l; TRI_shape_sid_t l;
TRI_shape_size_t* offsets; TRI_shape_size_t* offsets;
TRI_shape_size_t offset; TRI_shape_size_t offset;
TRI_shape_t const* found;
char* ptr; char* ptr;
// sanity checks // sanity checks
TRI_ASSERT(json->_type == TRI_JSON_ARRAY); TRI_ASSERT(json->_type == TRI_JSON_ARRAY);
// check for special case "empty list" // check for special case "empty list"
n = json->_value._objects._length; size_t const n = json->_value._objects._length;
if (n == 0) { if (n == 0) {
dst->_type = TRI_SHAPE_LIST; dst->_type = TRI_SHAPE_LIST;
@ -505,29 +493,38 @@ static bool FillShapeValueList (TRI_shaper_t* shaper,
return true; return true;
} }
// convert into TRI_shape_value_t array // helper function to free shape values
p = (values = static_cast<TRI_shape_value_t*>(TRI_Allocate(shaper->_memoryZone, sizeof(TRI_shape_value_t) * n, true))); auto freeShapeValues = [] (TRI_memory_zone_t* zone, TRI_shape_value_t* values, TRI_shape_value_t* end) {
TRI_shape_value_t* p = values;
TRI_shape_value_t* e = end;
if (p == nullptr) { for (; p < e; ++p) {
if (p->_value != nullptr) {
TRI_Free(zone, p->_value);
}
}
TRI_Free(zone, values);
};
// convert into TRI_shape_value_t array
TRI_shape_value_t* values = static_cast<TRI_shape_value_t*>(TRI_Allocate(shaper->_memoryZone, sizeof(TRI_shape_value_t) * n, true));
if (values == nullptr) {
return false; return false;
} }
total = 0; uint64_t total = 0;
e = values + n;
for (i = 0; i < n; ++i, ++p) { TRI_shape_value_t* p = values;
for (size_t i = 0; i < n; ++i, ++p) {
TRI_json_t const* el = static_cast<TRI_json_t const*>(TRI_AtVector(&json->_value._objects, i)); TRI_json_t const* el = static_cast<TRI_json_t const*>(TRI_AtVector(&json->_value._objects, i));
bool ok = FillShapeValueJson(shaper, p, el, level + 1, create); bool ok = FillShapeValueJson(shaper, p, el, level + 1, create);
if (! ok) { if (! ok) {
for (e = p, p = values; p < e; ++p) { freeShapeValues(shaper->_memoryZone, values, p);
if (p->_value != nullptr) {
TRI_Free(shaper->_memoryZone, p->_value);
}
}
TRI_Free(shaper->_memoryZone, values);
return false; return false;
} }
@ -535,12 +532,14 @@ static bool FillShapeValueList (TRI_shaper_t* shaper,
} }
// check if this list is homogeneous // check if this list is homogeneous
hs = true; bool hs = true;
hl = true; bool hl = true;
s = values[0]._sid; s = values[0]._sid;
l = values[0]._size; l = values[0]._size;
p = values; p = values;
TRI_shape_value_t* const e = values + n; // end does not change
for (; p < e; ++p) { for (; p < e; ++p) {
if (p->_sid != s) { if (p->_sid != s) {
@ -558,14 +557,7 @@ static bool FillShapeValueList (TRI_shaper_t* shaper,
TRI_homogeneous_sized_list_shape_t* shape = static_cast<TRI_homogeneous_sized_list_shape_t*>(TRI_Allocate(shaper->_memoryZone, sizeof(TRI_homogeneous_sized_list_shape_t), true)); TRI_homogeneous_sized_list_shape_t* shape = static_cast<TRI_homogeneous_sized_list_shape_t*>(TRI_Allocate(shaper->_memoryZone, sizeof(TRI_homogeneous_sized_list_shape_t), true));
if (shape == nullptr) { if (shape == nullptr) {
for (p = values; p < e; ++p) { freeShapeValues(shaper->_memoryZone, values, e);
if (p->_value != nullptr) {
TRI_Free(shaper->_memoryZone, p->_value);
}
}
TRI_Free(shaper->_memoryZone, values);
return false; return false;
} }
@ -576,18 +568,11 @@ static bool FillShapeValueList (TRI_shaper_t* shaper,
shape->_sizeEntry = l; shape->_sizeEntry = l;
// note: if 'found' is not a nullptr, the shaper will have freed variable 'shape'! // note: if 'found' is not a nullptr, the shaper will have freed variable 'shape'!
found = shaper->findShape(shaper, &shape->base, create); TRI_shape_t const* found = shaper->findShape(shaper, &shape->base, create);
if (found == nullptr) { if (found == nullptr) {
for (p = values; p < e; ++p) { freeShapeValues(shaper->_memoryZone, values, e);
if (p->_value != nullptr) {
TRI_Free(shaper->_memoryZone, p->_value);
}
}
TRI_Free(shaper->_memoryZone, values);
TRI_Free(shaper->_memoryZone, shape); TRI_Free(shaper->_memoryZone, shape);
return false; return false;
} }
@ -601,14 +586,7 @@ static bool FillShapeValueList (TRI_shaper_t* shaper,
dst->_value = (ptr = static_cast<char*>(TRI_Allocate(shaper->_memoryZone, dst->_size, true))); dst->_value = (ptr = static_cast<char*>(TRI_Allocate(shaper->_memoryZone, dst->_size, true)));
if (dst->_value == nullptr) { if (dst->_value == nullptr) {
for (p = values; p < e; ++p) { freeShapeValues(shaper->_memoryZone, values, e);
if (p->_value != nullptr) {
TRI_Free(shaper->_memoryZone, p->_value);
}
}
TRI_Free(shaper->_memoryZone, values);
return false; return false;
} }
@ -627,14 +605,7 @@ static bool FillShapeValueList (TRI_shaper_t* shaper,
TRI_homogeneous_list_shape_t* shape = static_cast<TRI_homogeneous_list_shape_t*>(TRI_Allocate(shaper->_memoryZone, sizeof(TRI_homogeneous_list_shape_t), true)); TRI_homogeneous_list_shape_t* shape = static_cast<TRI_homogeneous_list_shape_t*>(TRI_Allocate(shaper->_memoryZone, sizeof(TRI_homogeneous_list_shape_t), true));
if (shape == nullptr) { if (shape == nullptr) {
for (p = values; p < e; ++p) { freeShapeValues(shaper->_memoryZone, values, e);
if (p->_value != nullptr) {
TRI_Free(shaper->_memoryZone, p->_value);
}
}
TRI_Free(shaper->_memoryZone, values);
return false; return false;
} }
@ -644,18 +615,11 @@ static bool FillShapeValueList (TRI_shaper_t* shaper,
shape->_sidEntry = s; shape->_sidEntry = s;
// note: if 'found' is not a nullptr, the shaper will have freed variable 'shape'! // note: if 'found' is not a nullptr, the shaper will have freed variable 'shape'!
found = shaper->findShape(shaper, &shape->base, create); TRI_shape_t const* found = shaper->findShape(shaper, &shape->base, create);
if (found == nullptr) { if (found == nullptr) {
for (p = values; p < e; ++p) { freeShapeValues(shaper->_memoryZone, values, e);
if (p->_value != nullptr) {
TRI_Free(shaper->_memoryZone, p->_value);
}
}
TRI_Free(shaper->_memoryZone, values);
TRI_Free(shaper->_memoryZone, shape); TRI_Free(shaper->_memoryZone, shape);
return false; return false;
} }
@ -671,14 +635,7 @@ static bool FillShapeValueList (TRI_shaper_t* shaper,
dst->_value = (ptr = static_cast<char*>(TRI_Allocate(shaper->_memoryZone, dst->_size, true))); dst->_value = (ptr = static_cast<char*>(TRI_Allocate(shaper->_memoryZone, dst->_size, true)));
if (dst->_value == nullptr) { if (dst->_value == nullptr) {
for (p = values; p < e; ++p) { freeShapeValues(shaper->_memoryZone, values, e);
if (p->_value != nullptr) {
TRI_Free(shaper->_memoryZone, p->_value);
}
}
TRI_Free(shaper->_memoryZone, values);
return false; return false;
} }
@ -715,13 +672,7 @@ static bool FillShapeValueList (TRI_shaper_t* shaper,
dst->_value = (ptr = static_cast<char*>(TRI_Allocate(shaper->_memoryZone, dst->_size, true))); dst->_value = (ptr = static_cast<char*>(TRI_Allocate(shaper->_memoryZone, dst->_size, true)));
if (dst->_value == nullptr) { if (dst->_value == nullptr) {
for (p = values; p < e; ++p) { freeShapeValues(shaper->_memoryZone, values, e);
if (p->_value != nullptr) {
TRI_Free(shaper->_memoryZone, p->_value);
}
}
TRI_Free(shaper->_memoryZone, values);
return false; return false;
} }
@ -749,13 +700,7 @@ static bool FillShapeValueList (TRI_shaper_t* shaper,
} }
// free TRI_shape_value_t array // free TRI_shape_value_t array
for (p = values; p < e; ++p) { freeShapeValues(shaper->_memoryZone, values, e);
if (p->_value != nullptr) {
TRI_Free(shaper->_memoryZone, p->_value);
}
}
TRI_Free(shaper->_memoryZone, values);
return true; return true;
} }
@ -768,26 +713,12 @@ static bool FillShapeValueArray (TRI_shaper_t* shaper,
TRI_json_t const* json, TRI_json_t const* json,
size_t level, size_t level,
bool create) { bool create) {
size_t i, n;
uint64_t total;
size_t f;
size_t v;
TRI_shape_value_t* values;
TRI_shape_value_t* p;
TRI_shape_value_t* e;
TRI_array_shape_t* a;
TRI_shape_sid_t* sids; TRI_shape_sid_t* sids;
TRI_shape_aid_t* aids; TRI_shape_aid_t* aids;
TRI_shape_size_t* offsetsF; TRI_shape_size_t* offsetsF;
TRI_shape_size_t* offsetsV; TRI_shape_size_t* offsetsV;
TRI_shape_size_t offset; TRI_shape_size_t offset;
TRI_shape_t const* found;
char* ptr; char* ptr;
// sanity checks // sanity checks
@ -795,20 +726,38 @@ static bool FillShapeValueArray (TRI_shaper_t* shaper,
TRI_ASSERT(json->_value._objects._length % 2 == 0); TRI_ASSERT(json->_value._objects._length % 2 == 0);
// number of attributes // number of attributes
n = json->_value._objects._length / 2; size_t n = json->_value._objects._length / 2;
// convert into TRI_shape_value_t array // convert into TRI_shape_value_t array
p = (values = static_cast<TRI_shape_value_t*>(TRI_Allocate(shaper->_memoryZone, n * sizeof(TRI_shape_value_t), true))); TRI_shape_value_t* values = static_cast<TRI_shape_value_t*>(TRI_Allocate(shaper->_memoryZone, n * sizeof(TRI_shape_value_t), true));
if (p == nullptr) { if (values == nullptr) {
return false; return false;
} }
total = 0;
f = 0;
v = 0;
for (i = 0; i < n; ++i, ++p) { // helper function to free shape values
auto freeShapeValues = [] (TRI_memory_zone_t* zone, TRI_shape_value_t* values, TRI_shape_value_t* end) {
TRI_shape_value_t* p = values;
TRI_shape_value_t* e = end;
for (; p < e; ++p) {
if (p->_value != nullptr) {
TRI_Free(zone, p->_value);
}
}
TRI_Free(zone, values);
};
uint64_t total = 0;
size_t f = 0;
size_t v = 0;
TRI_shape_value_t* p = values;
for (size_t i = 0; i < n; ++i, ++p) {
TRI_json_t const* key = static_cast<TRI_json_t const*>(TRI_AtVector(&json->_value._objects, 2 * i)); TRI_json_t const* key = static_cast<TRI_json_t const*>(TRI_AtVector(&json->_value._objects, 2 * i));
TRI_ASSERT(key != nullptr); TRI_ASSERT(key != nullptr);
TRI_ASSERT(key->_type == TRI_JSON_STRING); TRI_ASSERT(key->_type == TRI_JSON_STRING);
@ -851,13 +800,7 @@ static bool FillShapeValueArray (TRI_shaper_t* shaper,
} }
if (! ok) { if (! ok) {
for (e = p, p = values; p < e; ++p) { freeShapeValues(shaper->_memoryZone, values, p);
if (p->_value != nullptr) {
TRI_Free(shaper->_memoryZone, p->_value);
}
}
TRI_Free(shaper->_memoryZone, values);
return false; return false;
} }
@ -893,30 +836,21 @@ static bool FillShapeValueArray (TRI_shaper_t* shaper,
#endif #endif
// generate shape structure // generate shape structure
i = size_t byteSize =
sizeof(TRI_array_shape_t) sizeof(TRI_array_shape_t)
+ n * sizeof(TRI_shape_sid_t) + n * sizeof(TRI_shape_sid_t)
+ n * sizeof(TRI_shape_aid_t) + n * sizeof(TRI_shape_aid_t)
+ (f + 1) * sizeof(TRI_shape_size_t); + (f + 1) * sizeof(TRI_shape_size_t);
a = reinterpret_cast<TRI_array_shape_t*>(ptr = static_cast<char*>(TRI_Allocate(shaper->_memoryZone, i, true))); TRI_array_shape_t* a = reinterpret_cast<TRI_array_shape_t*>(ptr = static_cast<char*>(TRI_Allocate(shaper->_memoryZone, byteSize, true)));
if (ptr == nullptr) { if (ptr == nullptr) {
e = values + n; freeShapeValues(shaper->_memoryZone, values, values + n);
for (p = values; p < e; ++p) {
if (p->_value != nullptr) {
TRI_Free(shaper->_memoryZone, p->_value);
}
}
TRI_Free(shaper->_memoryZone, values);
return false; return false;
} }
a->base._type = TRI_SHAPE_ARRAY; a->base._type = TRI_SHAPE_ARRAY;
a->base._size = i; a->base._size = byteSize;
a->base._dataSize = (v == 0) ? total : TRI_SHAPE_SIZE_VARIABLE; a->base._dataSize = (v == 0) ? total : TRI_SHAPE_SIZE_VARIABLE;
a->_fixedEntries = f; a->_fixedEntries = f;
@ -944,17 +878,8 @@ static bool FillShapeValueArray (TRI_shaper_t* shaper,
dst->_value = (ptr = static_cast<char*>(TRI_Allocate(shaper->_memoryZone, dst->_size, true))); dst->_value = (ptr = static_cast<char*>(TRI_Allocate(shaper->_memoryZone, dst->_size, true)));
if (ptr == nullptr) { if (ptr == nullptr) {
e = values + n; freeShapeValues(shaper->_memoryZone, values, values + n);
for (p = values; p < e; ++p) {
if (p->_value != nullptr) {
TRI_Free(shaper->_memoryZone, p->_value);
}
}
TRI_Free(shaper->_memoryZone, values);
TRI_Free(shaper->_memoryZone, a); TRI_Free(shaper->_memoryZone, a);
return false; return false;
} }
@ -963,7 +888,7 @@ static bool FillShapeValueArray (TRI_shaper_t* shaper,
ptr += (v + 1) * sizeof(TRI_shape_size_t); ptr += (v + 1) * sizeof(TRI_shape_size_t);
// and fill in attributes // and fill in attributes
e = values + n; TRI_shape_value_t* const e = values + n;
for (p = values; p < e; ++p) { for (p = values; p < e; ++p) {
*aids++ = p->_aid; *aids++ = p->_aid;
@ -987,16 +912,10 @@ static bool FillShapeValueArray (TRI_shaper_t* shaper,
} }
// free TRI_shape_value_t array // free TRI_shape_value_t array
for (p = values; p < e; ++p) { freeShapeValues(shaper->_memoryZone, values, e);
if (p->_value != nullptr) {
TRI_Free(shaper->_memoryZone, p->_value);
}
}
TRI_Free(shaper->_memoryZone, values);
// lookup this shape // lookup this shape
found = shaper->findShape(shaper, &a->base, create); TRI_shape_t const* found = shaper->findShape(shaper, &a->base, create);
if (found == nullptr) { if (found == nullptr) {
TRI_Free(shaper->_memoryZone, dst->_value); TRI_Free(shaper->_memoryZone, dst->_value);