Browse Source

Merge pull request #22788 from Faless/warnings_fix

Some warnings fix
Rémi Verschelde 7 years ago
parent
commit
5676632a3b

+ 2 - 3
core/io/marshalls.cpp

@@ -850,17 +850,16 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
 		} break;
 		case Variant::INT: {
 
-			int64_t val = p_variant;
 			if (flags & ENCODE_FLAG_64) {
 				//64 bits
 				if (buf) {
-					encode_uint64(val, buf);
+					encode_uint64(p_variant.operator int64_t(), buf);
 				}
 
 				r_len += 8;
 			} else {
 				if (buf) {
-					encode_uint32(int32_t(val), buf);
+					encode_uint32(p_variant.operator int32_t(), buf);
 				}
 
 				r_len += 4;

+ 1 - 3
core/os/rw_lock.h

@@ -57,9 +57,7 @@ class RWLockRead {
 
 public:
 	RWLockRead(const RWLock *p_lock) {
-		if (p_lock) {
-			lock = const_cast<RWLock *>(p_lock);
-		}
+		lock = const_cast<RWLock *>(p_lock);
 		if (lock) lock->read_lock();
 	}
 	~RWLockRead() {

+ 3 - 3
drivers/unix/dir_access_unix.cpp

@@ -309,7 +309,7 @@ Error DirAccessUnix::change_dir(String p_dir) {
 	// prev_dir is the directory we are changing out of
 	String prev_dir;
 	char real_current_dir_name[2048];
-	getcwd(real_current_dir_name, 2048);
+	ERR_FAIL_COND_V(getcwd(real_current_dir_name, 2048) == NULL, ERR_BUG);
 	if (prev_dir.parse_utf8(real_current_dir_name))
 		prev_dir = real_current_dir_name; //no utf8, maybe latin?
 
@@ -330,7 +330,7 @@ Error DirAccessUnix::change_dir(String p_dir) {
 
 	// the directory exists, so set current_dir to try_dir
 	current_dir = try_dir;
-	chdir(prev_dir.utf8().get_data());
+	ERR_FAIL_COND_V(chdir(prev_dir.utf8().get_data()) != 0, ERR_BUG);
 	return OK;
 }
 
@@ -405,7 +405,7 @@ DirAccessUnix::DirAccessUnix() {
 
 	// set current directory to an absolute path of the current directory
 	char real_current_dir_name[2048];
-	getcwd(real_current_dir_name, 2048);
+	ERR_FAIL_COND(getcwd(real_current_dir_name, 2048) == NULL);
 	if (current_dir.parse_utf8(real_current_dir_name))
 		current_dir = real_current_dir_name;
 

+ 4 - 2
drivers/unix/os_unix.cpp

@@ -487,9 +487,11 @@ String OS_Unix::get_executable_path() const {
 	//fix for running from a symlink
 	char buf[256];
 	memset(buf, 0, 256);
-	readlink("/proc/self/exe", buf, sizeof(buf));
+	ssize_t len = readlink("/proc/self/exe", buf, sizeof(buf));
 	String b;
-	b.parse_utf8(buf);
+	if (len > 0) {
+		b.parse_utf8(buf, len);
+	}
 	if (b == "") {
 		WARN_PRINT("Couldn't get executable path from /proc/self/exe, using argv[0]");
 		return OS::get_executable_path();

+ 6 - 3
modules/websocket/lws_client.cpp

@@ -80,9 +80,12 @@ Error LWSClient::connect_to_host(String p_host, String p_path, uint16_t p_port,
 	char hbuf[1024];
 	char pbuf[2048];
 	String addr_str = (String)addr;
-	strncpy(abuf, addr_str.ascii().get_data(), 1024);
-	strncpy(hbuf, p_host.utf8().get_data(), 1024);
-	strncpy(pbuf, p_path.utf8().get_data(), 2048);
+	strncpy(abuf, addr_str.ascii().get_data(), 1023);
+	abuf[1023] = '\0';
+	strncpy(hbuf, p_host.utf8().get_data(), 1023);
+	hbuf[1023] = '\0';
+	strncpy(pbuf, p_path.utf8().get_data(), 2047);
+	pbuf[2047] = '\0';
 
 	i.context = context;
 	if (p_protocols.size() > 0)

+ 3 - 2
platform/x11/godot_x11.cpp

@@ -43,7 +43,7 @@ int main(int argc, char *argv[]) {
 	setlocale(LC_CTYPE, "");
 
 	char *cwd = (char *)malloc(PATH_MAX);
-	getcwd(cwd, PATH_MAX);
+	char *ret = getcwd(cwd, PATH_MAX);
 
 	Error err = Main::setup(argv[0], argc - 1, &argv[1]);
 	if (err != OK) {
@@ -55,7 +55,8 @@ int main(int argc, char *argv[]) {
 		os.run(); // it is actually the OS that decides how to run
 	Main::cleanup();
 
-	chdir(cwd);
+	if (ret)
+		chdir(cwd);
 	free(cwd);
 
 	return os.get_exit_code();