Quellcode durchsuchen

src: fix cppcheck warnings

Daniele Bartolini vor 5 Jahren
Ursprung
Commit
ac13e2a034

+ 18 - 17
src/core/filesystem/file_monitor_windows.cpp

@@ -32,6 +32,7 @@ struct FileMonitorImpl
 		explicit Watch(Allocator& a)
 			: _path(a)
 		{
+			memset(&_buffer, 0, sizeof(_buffer));
 			memset(&_overlapped, 0, sizeof(_overlapped));
 		}
 
@@ -85,32 +86,32 @@ struct FileMonitorImpl
 		_iocp = CreateIoCompletionPort(fh, _iocp, _key, 0);
 		CE_ASSERT(_iocp != NULL, "CreateIoCompletionPort: GetLastError: %d", GetLastError());
 
-		Watch* watch = CE_NEW(*_allocator, Watch)(*_allocator);
-		watch->_path = path;
-		watch->_handle = fh;
+		Watch* wh = CE_NEW(*_allocator, Watch)(*_allocator);
+		wh->_path = path;
+		wh->_handle = fh;
 
 		BOOL rdc = ReadDirectoryChangesW(fh
-			, &watch->_buffer
-			, sizeof(watch->_buffer)
+			, &wh->_buffer
+			, sizeof(wh->_buffer)
 			, _recursive
 			, FILE_NOTIFY_CHANGE_FILE_NAME
 			| FILE_NOTIFY_CHANGE_DIR_NAME
 			| FILE_NOTIFY_CHANGE_ATTRIBUTES
 			| FILE_NOTIFY_CHANGE_SIZE
 			, NULL
-			, &watch->_overlapped
+			, &wh->_overlapped
 			, NULL
 			);
 		CE_ASSERT(rdc != 0, "ReadDirectoryChangesW: GetLastError: %d", GetLastError());
 
-		hash_map::set(_watches, _key, watch);
+		hash_map::set(_watches, _key, wh);
 		++_key;
 	}
 
 	void scan_subdirectories(const char* path)
 	{
-		TempAllocator256 ta;
-		DynamicString dir(ta);
+		TempAllocator256 dir_ta;
+		DynamicString dir(dir_ta);
 		dir += path;
 		dir += "\\*";
 
@@ -197,12 +198,12 @@ struct FileMonitorImpl
 			if (bytes_transferred == 0)
 				continue;
 
-			Watch* watch = hash_map::get(_watches, (u32)(uintptr_t)key, (Watch*)NULL);
+			Watch* wh = hash_map::get(_watches, (u32)(uintptr_t)key, (Watch*)NULL);
 
 			// Read packets
 			DWORD last_action = -1;
 			DynamicString path_old_name(default_allocator());
-			char* cur = (char*)watch->_buffer;
+			char* cur = (char*)wh->_buffer;
 			for(;;)
 			{
 				const FILE_NOTIFY_INFORMATION* fni = (const FILE_NOTIFY_INFORMATION*)cur;
@@ -279,16 +280,16 @@ struct FileMonitorImpl
 				cur += fni->NextEntryOffset;
 			}
 
-			BOOL rdc = ReadDirectoryChangesW(watch->_handle
-				, &watch->_buffer
-				, sizeof(watch->_buffer)
+			BOOL rdc = ReadDirectoryChangesW(wh->_handle
+				, &wh->_buffer
+				, sizeof(wh->_buffer)
 				, _recursive
 				, FILE_NOTIFY_CHANGE_FILE_NAME
 				| FILE_NOTIFY_CHANGE_DIR_NAME
 				| FILE_NOTIFY_CHANGE_ATTRIBUTES
 				| FILE_NOTIFY_CHANGE_SIZE
 				, NULL
-				, &watch->_overlapped
+				, &wh->_overlapped
 				, NULL
 				);
 			CE_ASSERT(rdc != 0, "ReadDirectoryChangesW: GetLastError: %d", GetLastError());
@@ -299,11 +300,11 @@ struct FileMonitorImpl
 
 	void full_path(DynamicString& path, u32 key, const WCHAR* name, u32 name_len)
 	{
-		Watch* watch = hash_map::get(_watches, key, (Watch*)NULL);
+		Watch* wh = hash_map::get(_watches, key, (Watch*)NULL);
 
 		TempAllocator512 ta;
 		DynamicString path_base(ta);
-		path_base = watch->_path;
+		path_base = wh->_path;
 		DynamicString filename(ta);
 		for (u32 ii = 0; ii < name_len/2; ++ii)
 			filename += (char)name[ii];

+ 2 - 2
src/core/os.cpp

@@ -252,8 +252,8 @@ namespace os
 			closedir(dir);
 		}
 #elif CROWN_PLATFORM_WINDOWS
-		TempAllocator256 ta;
-		DynamicString cur_path(ta);
+		TempAllocator256 ta_path;
+		DynamicString cur_path(ta_path);
 		cur_path += path;
 		cur_path += "\\*";
 

+ 1 - 1
src/device/console_server.cpp

@@ -76,7 +76,7 @@ namespace console_server_internal
 		}
 	}
 
-	static u32 add_client(ConsoleServer& cs, TCPSocket& socket)
+	static u32 add_client(ConsoleServer& cs, const TCPSocket& socket)
 	{
 		const u32 id = cs._next_client_id++;
 

+ 15 - 9
src/device/main_linux.cpp

@@ -174,18 +174,24 @@ struct JoypadEvent
 
 struct Joypad
 {
-	int _fd[CROWN_MAX_JOYPADS];
-	bool _connected[CROWN_MAX_JOYPADS];
-
 	struct AxisData
 	{
 		s16 left[3];
 		s16 right[3];
 	};
 
+	int _fd[CROWN_MAX_JOYPADS];
+	bool _connected[CROWN_MAX_JOYPADS];
 	AxisData _axis[CROWN_MAX_JOYPADS];
 
-	void init()
+	Joypad()
+	{
+		memset(&_fd, 0, sizeof(_fd));
+		memset(&_connected, 0, sizeof(_connected));
+		memset(&_axis, 0, sizeof(_axis));
+	}
+
+	void open()
 	{
 		char jspath[] = "/dev/input/jsX";
 		char* num = strchr(jspath, 'X');
@@ -193,19 +199,19 @@ struct Joypad
 		for (u8 i = 0; i < CROWN_MAX_JOYPADS; ++i)
 		{
 			*num = '0' + i;
-			_fd[i] = open(jspath, O_RDONLY | O_NONBLOCK);
+			_fd[i] = ::open(jspath, O_RDONLY | O_NONBLOCK);
 		}
 
 		memset(_connected, 0, sizeof(_connected));
 		memset(_axis, 0, sizeof(_axis));
 	}
 
-	void shutdown()
+	void close()
 	{
 		for (u8 i = 0; i < CROWN_MAX_JOYPADS; ++i)
 		{
 			if (_fd[i] != -1)
-				close(_fd[i]);
+				::close(_fd[i]);
 		}
 	}
 
@@ -407,7 +413,7 @@ struct LinuxDevice
 			, opts
 			);
 
-		_joypad.init();
+		_joypad.open();
 
 		while (!s_exit)
 		{
@@ -584,7 +590,7 @@ struct LinuxDevice
 			}
 		}
 
-		_joypad.shutdown();
+		_joypad.close();
 
 		main_thread.stop();
 

+ 1 - 1
src/device/main_windows.cpp

@@ -158,7 +158,7 @@ struct Joypad
 	Axis _axis[CROWN_MAX_JOYPADS];
 	bool _connected[CROWN_MAX_JOYPADS];
 
-	void init()
+	Joypad()
 	{
 		memset(&_state, 0, sizeof(_state));
 		memset(&_axis, 0, sizeof(_axis));

+ 26 - 11
src/resource/data_compiler.cpp

@@ -188,7 +188,7 @@ struct LineReader
 		line.set(s, u32(nl - s));
 	}
 
-	bool eof()
+	bool eof() const
 	{
 		return _str[_pos] == '\0';
 	}
@@ -289,14 +289,8 @@ static Buffer read(FilesystemDisk& data_fs, const char* filename)
 	return buffer;
 }
 
-static void read_data_versions(HashMap<DynamicString, u32>& versions, FilesystemDisk& data_fs, const char* filename)
+static void parse_data_versions(HashMap<DynamicString, u32>& versions, const JsonObject& obj)
 {
-	Buffer json = read(data_fs, filename);
-
-	TempAllocator512 ta;
-	JsonObject obj(ta);
-	sjson::parse(obj, json);
-
 	auto cur = json_object::begin(obj);
 	auto end = json_object::end(obj);
 	for (; cur != end; ++cur)
@@ -311,7 +305,7 @@ static void read_data_versions(HashMap<DynamicString, u32>& versions, Filesystem
 	}
 }
 
-static void read_data_index(HashMap<StringId64, DynamicString>& index, FilesystemDisk& data_fs, const char* filename, const SourceIndex& sources)
+static void read_data_versions(HashMap<DynamicString, u32>& versions, FilesystemDisk& data_fs, const char* filename)
 {
 	Buffer json = read(data_fs, filename);
 
@@ -319,6 +313,11 @@ static void read_data_index(HashMap<StringId64, DynamicString>& index, Filesyste
 	JsonObject obj(ta);
 	sjson::parse(obj, json);
 
+	parse_data_versions(versions, obj);
+}
+
+static void parse_data_index(HashMap<StringId64, DynamicString>& index, const JsonObject& obj, const SourceIndex& sources)
+{
 	auto cur = json_object::begin(obj);
 	auto end = json_object::end(obj);
 	for (; cur != end; ++cur)
@@ -340,14 +339,19 @@ static void read_data_index(HashMap<StringId64, DynamicString>& index, Filesyste
 	}
 }
 
-static void read_data_mtimes(HashMap<StringId64, u64>& mtimes, FilesystemDisk& data_fs, const char* filename, const HashMap<StringId64, DynamicString>& data_index)
+static void read_data_index(HashMap<StringId64, DynamicString>& index, FilesystemDisk& data_fs, const char* filename, const SourceIndex& sources)
 {
 	Buffer json = read(data_fs, filename);
 
-	TempAllocator128 ta;
+	TempAllocator512 ta;
 	JsonObject obj(ta);
 	sjson::parse(obj, json);
 
+	parse_data_index(index, obj, sources);
+}
+
+static void parse_data_mtimes(HashMap<StringId64, u64>& mtimes, const JsonObject& obj, const HashMap<StringId64, DynamicString>& data_index)
+{
 	auto cur = json_object::begin(obj);
 	auto end = json_object::end(obj);
 	for (; cur != end; ++cur)
@@ -371,6 +375,17 @@ static void read_data_mtimes(HashMap<StringId64, u64>& mtimes, FilesystemDisk& d
 	}
 }
 
+static void read_data_mtimes(HashMap<StringId64, u64>& mtimes, FilesystemDisk& data_fs, const char* filename, const HashMap<StringId64, DynamicString>& data_index)
+{
+	Buffer json = read(data_fs, filename);
+
+	TempAllocator128 ta;
+	JsonObject obj(ta);
+	sjson::parse(obj, json);
+
+	parse_data_mtimes(mtimes, obj, data_index);
+}
+
 static void add_dependency_internal(HashMap<StringId64, HashMap<DynamicString, u32> >& dependencies, ResourceId id, const DynamicString& dependency)
 {
 	HashMap<DynamicString, u32> deps_deffault(default_allocator());

+ 5 - 5
src/world/animation_state_machine.cpp

@@ -143,9 +143,9 @@ void AnimationStateMachine::update(float dt)
 	f32 stack_data[32];
 	skinny::expression_language::Stack stack(stack_data, countof(stack_data));
 
-	for (u32 i = 0; i < array::size(_animations); ++i)
+	for (u32 ii = 0; ii < array::size(_animations); ++ii)
 	{
-		Animation& anim_i = _animations[i];
+		Animation& anim_i = _animations[ii];
 
 		const f32* variables = anim_i.variables;
 		const u32* byte_code = state_machine::byte_code(anim_i.state_machine);
@@ -156,9 +156,9 @@ void AnimationStateMachine::update(float dt)
 		StringId64 name;
 
 		const AnimationArray* aa = state_machine::state_animations(anim_i.state);
-		for (u32 i = 0; i < aa->num; ++i)
+		for (u32 jj = 0; jj < aa->num; ++jj)
 		{
-			const crown::Animation* animation = state_machine::animation(aa, i);
+			const crown::Animation* animation = state_machine::animation(aa, jj);
 
 			stack.size = 0;
 			skinny::expression_language::run(&byte_code[animation->bytecode_entry], variables, stack);
@@ -166,7 +166,7 @@ void AnimationStateMachine::update(float dt)
 			if (cur > max_v || max_i == UINT32_MAX)
 			{
 				max_v = cur;
-				max_i = i;
+				max_i = jj;
 				name = animation->name;
 			}
 		}