2
0
Эх сурвалжийг харах

src: fix random stuff found by cppcheck

Daniele Bartolini 3 жил өмнө
parent
commit
75e51c5eda

+ 4 - 8
src/core/containers/hash_map.inl

@@ -180,7 +180,7 @@ namespace hash_map_internal
 		nm._mask = new_capacity - 1;
 
 		for (u32 i = 0; i < m._capacity; ++i) {
-			typename HashMap<TKey, TValue, Hash, KeyEqual>::Entry &e = m._data[i];
+			const typename HashMap<TKey, TValue, Hash, KeyEqual>::Entry &e = m._data[i];
 			const u32 hash = m._index[i].hash;
 			const u32 index = m._index[i].index;
 
@@ -325,17 +325,13 @@ inline HashMap<TKey, TValue, Hash, KeyEqual>::HashMap(Allocator &a)
 template<typename TKey, typename TValue, typename Hash, typename KeyEqual>
 HashMap<TKey, TValue, Hash, KeyEqual>::HashMap(const HashMap<TKey, TValue, Hash, KeyEqual> &other)
 	: _allocator(other._allocator)
-	, _capacity(0)
-	, _size(0)
-	, _mask(0)
+	, _capacity(other._capacity)
+	, _size(other._size)
+	, _mask(other._mask)
 	, _index(NULL)
 	, _data(NULL)
 	, _buffer(NULL)
 {
-	_capacity = other._capacity;
-	_size = other._size;
-	_mask = other._mask;
-
 	if (other._capacity > 0) {
 		_allocator->deallocate(_buffer);
 		const u32 size = other._capacity * (sizeof(Index) + sizeof(Entry)) + alignof(Index) + alignof(Entry);

+ 4 - 9
src/core/containers/hash_set.inl

@@ -177,12 +177,11 @@ namespace hash_set_internal
 		nm._mask = new_capacity - 1;
 
 		for (u32 i = 0; i < m._capacity; ++i) {
-			TKey &e = m._data[i];
 			const u32 hash = m._index[i].hash;
 			const u32 index = m._index[i].index;
 
 			if (index != FREE && !is_deleted(index))
-				hash_set_internal::insert(nm, hash, e);
+				hash_set_internal::insert(nm, hash, m._data[i]);
 		}
 
 		HashSet<TKey, Hash, KeyEqual> empty(*m._allocator);
@@ -304,17 +303,13 @@ inline HashSet<TKey, Hash, KeyEqual>::HashSet(Allocator &a)
 template<typename TKey, typename Hash, typename KeyEqual>
 HashSet<TKey, Hash, KeyEqual>::HashSet(const HashSet &other)
 	: _allocator(other._allocator)
-	, _capacity(0)
-	, _size(0)
-	, _mask(0)
+	, _capacity(other._capacity)
+	, _size(other._size)
+	, _mask(other._mask)
 	, _index(NULL)
 	, _data(NULL)
 	, _buffer(NULL)
 {
-	_capacity = other._capacity;
-	_size = other._size;
-	_mask = other._mask;
-
 	if (other._capacity > 0) {
 		_allocator->deallocate(_buffer);
 		const u32 size = other._capacity * (sizeof(Index) + sizeof(TKey)) + alignof(Index) + alignof(TKey);

+ 3 - 3
src/core/math/frustum.inl

@@ -113,11 +113,11 @@ namespace frustum
 
 	inline AABB to_aabb(const Frustum &f)
 	{
-		Vector3 vertices[8];
-		frustum::vertices(vertices, f);
+		Vector3 verts[8];
+		frustum::vertices(verts, f);
 
 		AABB r;
-		aabb::from_points(r, countof(vertices), vertices);
+		aabb::from_points(r, countof(verts), verts);
 		return r;
 	}
 

+ 1 - 1
src/core/memory/globals.cpp

@@ -251,7 +251,7 @@ namespace memory
 			_backing.deallocate(_begin);
 		}
 
-		bool in_use(void *p)
+		bool in_use(const void *p)
 		{
 			if (_free == _allocate)
 				return false;

+ 2 - 2
src/core/unit_tests.cpp

@@ -909,7 +909,7 @@ static void test_string_id()
 		ENSURE(a._id == 0x7c2365dbu);
 
 		StringId32 b("murmur32", 8);
-		ENSURE(a._id == 0x7c2365dbu);
+		ENSURE(b._id == 0x7c2365dbu);
 
 		char str[9];
 		a.to_string(str, sizeof(str));
@@ -920,7 +920,7 @@ static void test_string_id()
 		ENSURE(a._id == 0x90631502d1a3432bu);
 
 		StringId64 b("murmur64", 8);
-		ENSURE(a._id == 0x90631502d1a3432bu);
+		ENSURE(b._id == 0x90631502d1a3432bu);
 
 		char str[17];
 		a.to_string(str, sizeof(str));

+ 1 - 1
src/world/physics_world_bullet.cpp

@@ -301,7 +301,7 @@ struct PhysicsWorldImpl
 			break;
 
 		case ColliderType::CONVEX_HULL: {
-			const char *data       = (char *)&sd[1];
+			const u8 *data         = (u8 *)&sd[1];
 			const u32 num          = *(u32 *)data;
 			const btScalar *points = (btScalar *)(data + sizeof(u32));
 

+ 1 - 1
src/world/unit_manager.cpp

@@ -22,7 +22,7 @@ UnitManager::UnitManager(Allocator &a)
 
 UnitId UnitManager::make_unit(u32 idx, u8 gen)
 {
-	UnitId unit = { 0 | idx | u32(gen) << UNIT_INDEX_BITS };
+	UnitId unit = { idx | u32(gen) << UNIT_INDEX_BITS };
 	return unit;
 }