Fix compilation warnings in JS and Windows builds

Warnings raised by Emscripten 1.38.0 and MinGW64 5.0.4 / GCC 8.3.0.

JS can now build with `werror=yes warnings=extra`.
MinGW64 still has a few warnings to resolve with `warnings=extra`,
and only one with `warnings=all`.

Part of #29033 and #29801.
This commit is contained in:
Rémi Verschelde 2019-06-15 12:11:30 +02:00
parent 0a3c21d999
commit 68735d2a88
11 changed files with 44 additions and 39 deletions

View file

@ -306,7 +306,7 @@ Error NetSocketPosix::bind(IP_Address p_addr, uint16_t p_port) {
sockaddr_storage addr; sockaddr_storage addr;
size_t addr_size = _set_addr_storage(&addr, p_addr, p_port, _ip_type); size_t addr_size = _set_addr_storage(&addr, p_addr, p_port, _ip_type);
if (::bind(_sock, (struct sockaddr *)&addr, addr_size) == SOCK_EMPTY) { if (::bind(_sock, (struct sockaddr *)&addr, addr_size) != 0) {
close(); close();
ERR_FAIL_V(ERR_UNAVAILABLE); ERR_FAIL_V(ERR_UNAVAILABLE);
} }
@ -317,7 +317,7 @@ Error NetSocketPosix::bind(IP_Address p_addr, uint16_t p_port) {
Error NetSocketPosix::listen(int p_max_pending) { Error NetSocketPosix::listen(int p_max_pending) {
ERR_FAIL_COND_V(!is_open(), ERR_UNCONFIGURED); ERR_FAIL_COND_V(!is_open(), ERR_UNCONFIGURED);
if (::listen(_sock, p_max_pending) == SOCK_EMPTY) { if (::listen(_sock, p_max_pending) != 0) {
close(); close();
ERR_FAIL_V(FAILED); ERR_FAIL_V(FAILED);
@ -334,7 +334,7 @@ Error NetSocketPosix::connect_to_host(IP_Address p_host, uint16_t p_port) {
struct sockaddr_storage addr; struct sockaddr_storage addr;
size_t addr_size = _set_addr_storage(&addr, p_host, p_port, _ip_type); size_t addr_size = _set_addr_storage(&addr, p_host, p_port, _ip_type);
if (::connect(_sock, (struct sockaddr *)&addr, addr_size) == SOCK_EMPTY) { if (::connect(_sock, (struct sockaddr *)&addr, addr_size) != 0) {
NetError err = _get_socket_error(); NetError err = _get_socket_error();

View file

@ -167,13 +167,13 @@ Error AudioDriverWASAPI::audio_device_init(AudioDeviceWASAPI *p_device, bool p_c
ERR_FAIL_COND_V(hr != S_OK, ERR_CANT_OPEN); ERR_FAIL_COND_V(hr != S_OK, ERR_CANT_OPEN);
for (ULONG i = 0; i < count && !found; i++) { for (ULONG i = 0; i < count && !found; i++) {
IMMDevice *device = NULL; IMMDevice *tmp_device = NULL;
hr = devices->Item(i, &device); hr = devices->Item(i, &tmp_device);
ERR_BREAK(hr != S_OK); ERR_BREAK(hr != S_OK);
IPropertyStore *props = NULL; IPropertyStore *props = NULL;
hr = device->OpenPropertyStore(STGM_READ, &props); hr = tmp_device->OpenPropertyStore(STGM_READ, &props);
ERR_BREAK(hr != S_OK); ERR_BREAK(hr != S_OK);
PROPVARIANT propvar; PROPVARIANT propvar;
@ -183,7 +183,7 @@ Error AudioDriverWASAPI::audio_device_init(AudioDeviceWASAPI *p_device, bool p_c
ERR_BREAK(hr != S_OK); ERR_BREAK(hr != S_OK);
if (p_device->device_name == String(propvar.pwszVal)) { if (p_device->device_name == String(propvar.pwszVal)) {
hr = device->GetId(&strId); hr = tmp_device->GetId(&strId);
ERR_BREAK(hr != S_OK); ERR_BREAK(hr != S_OK);
found = true; found = true;
@ -191,7 +191,7 @@ Error AudioDriverWASAPI::audio_device_init(AudioDeviceWASAPI *p_device, bool p_c
PropVariantClear(&propvar); PropVariantClear(&propvar);
props->Release(); props->Release();
device->Release(); tmp_device->Release();
} }
if (found) { if (found) {
@ -289,7 +289,7 @@ Error AudioDriverWASAPI::audio_device_init(AudioDeviceWASAPI *p_device, bool p_c
} }
DWORD streamflags = 0; DWORD streamflags = 0;
if (mix_rate != pwfex->nSamplesPerSec) { if ((DWORD)mix_rate != pwfex->nSamplesPerSec) {
streamflags |= AUDCLNT_STREAMFLAGS_RATEADJUST; streamflags |= AUDCLNT_STREAMFLAGS_RATEADJUST;
pwfex->nSamplesPerSec = mix_rate; pwfex->nSamplesPerSec = mix_rate;
pwfex->nAvgBytesPerSec = pwfex->nSamplesPerSec * pwfex->nChannels * (pwfex->wBitsPerSample / 8); pwfex->nAvgBytesPerSec = pwfex->nSamplesPerSec * pwfex->nChannels * (pwfex->wBitsPerSample / 8);
@ -571,7 +571,7 @@ void AudioDriverWASAPI::thread_func(void *p_udata) {
if (ad->audio_output.active) { if (ad->audio_output.active) {
ad->audio_server_process(ad->buffer_frames, ad->samples_in.ptrw()); ad->audio_server_process(ad->buffer_frames, ad->samples_in.ptrw());
} else { } else {
for (unsigned int i = 0; i < ad->samples_in.size(); i++) { for (int i = 0; i < ad->samples_in.size(); i++) {
ad->samples_in.write[i] = 0; ad->samples_in.write[i] = 0;
} }
} }
@ -699,7 +699,7 @@ void AudioDriverWASAPI::thread_func(void *p_udata) {
ERR_BREAK(hr != S_OK); ERR_BREAK(hr != S_OK);
// fixme: Only works for floating point atm // fixme: Only works for floating point atm
for (int j = 0; j < num_frames_available; j++) { for (UINT32 j = 0; j < num_frames_available; j++) {
int32_t l, r; int32_t l, r;
if (flags & AUDCLNT_BUFFERFLAGS_SILENT) { if (flags & AUDCLNT_BUFFERFLAGS_SILENT) {

View file

@ -93,7 +93,7 @@ Error FileAccessWindows::_open(const String &p_path, int p_mode_flags) {
// a file using the wrong case (which *works* on Windows, but won't on other // a file using the wrong case (which *works* on Windows, but won't on other
// platforms). // platforms).
if (p_mode_flags == READ) { if (p_mode_flags == READ) {
WIN32_FIND_DATAW d = { 0 }; WIN32_FIND_DATAW d;
HANDLE f = FindFirstFileW(path.c_str(), &d); HANDLE f = FindFirstFileW(path.c_str(), &d);
if (f) { if (f) {
String fname = d.cFileName; String fname = d.cFileName;
@ -302,7 +302,7 @@ void FileAccessWindows::store_buffer(const uint8_t *p_src, int p_length) {
} }
prev_op = WRITE; prev_op = WRITE;
} }
ERR_FAIL_COND(fwrite(p_src, 1, p_length, f) != p_length); ERR_FAIL_COND(fwrite(p_src, 1, p_length, f) != (size_t)p_length);
} }
bool FileAccessWindows::file_exists(const String &p_name) { bool FileAccessWindows::file_exists(const String &p_name) {

View file

@ -68,7 +68,7 @@ void WebRTCDataChannelJS::_on_error() {
} }
void WebRTCDataChannelJS::_on_message(uint8_t *p_data, uint32_t p_size, bool p_is_string) { void WebRTCDataChannelJS::_on_message(uint8_t *p_data, uint32_t p_size, bool p_is_string) {
if (in_buffer.space_left() < p_size + 5) { if (in_buffer.space_left() < (int)(p_size + 5)) {
ERR_EXPLAIN("Buffer full! Dropping data"); ERR_EXPLAIN("Buffer full! Dropping data");
ERR_FAIL(); ERR_FAIL();
} }

View file

@ -99,7 +99,7 @@ Error AudioDriverJavaScript::init() {
return FAILED; return FAILED;
} }
if (!internal_buffer || memarr_len(internal_buffer) != buffer_length * channel_count) { if (!internal_buffer || (int)memarr_len(internal_buffer) != buffer_length * channel_count) {
if (internal_buffer) if (internal_buffer)
memdelete_arr(internal_buffer); memdelete_arr(internal_buffer);
internal_buffer = memnew_arr(float, buffer_length *channel_count); internal_buffer = memnew_arr(float, buffer_length *channel_count);

View file

@ -103,17 +103,17 @@ bool JoypadWindows::is_xinput_device(const GUID *p_guid) {
PRAWINPUTDEVICELIST dev_list = NULL; PRAWINPUTDEVICELIST dev_list = NULL;
unsigned int dev_list_count = 0; unsigned int dev_list_count = 0;
if (GetRawInputDeviceList(NULL, &dev_list_count, sizeof(RAWINPUTDEVICELIST)) == -1) { if (GetRawInputDeviceList(NULL, &dev_list_count, sizeof(RAWINPUTDEVICELIST)) == (UINT)-1) {
return false; return false;
} }
dev_list = (PRAWINPUTDEVICELIST)malloc(sizeof(RAWINPUTDEVICELIST) * dev_list_count); dev_list = (PRAWINPUTDEVICELIST)malloc(sizeof(RAWINPUTDEVICELIST) * dev_list_count);
if (!dev_list) return false; if (!dev_list) return false;
if (GetRawInputDeviceList(dev_list, &dev_list_count, sizeof(RAWINPUTDEVICELIST)) == -1) { if (GetRawInputDeviceList(dev_list, &dev_list_count, sizeof(RAWINPUTDEVICELIST)) == (UINT)-1) {
free(dev_list); free(dev_list);
return false; return false;
} }
for (int i = 0; i < dev_list_count; i++) { for (unsigned int i = 0; i < dev_list_count; i++) {
RID_DEVICE_INFO rdi; RID_DEVICE_INFO rdi;
char dev_name[128]; char dev_name[128];
@ -334,9 +334,9 @@ void JoypadWindows::process_joypads() {
if (joy.state.dwPacketNumber != joy.last_packet) { if (joy.state.dwPacketNumber != joy.last_packet) {
int button_mask = XINPUT_GAMEPAD_DPAD_UP; int button_mask = XINPUT_GAMEPAD_DPAD_UP;
for (int i = 0; i <= 16; i++) { for (int j = 0; j <= 16; i++) {
input->joy_button(joy.id, i, joy.state.Gamepad.wButtons & button_mask); input->joy_button(joy.id, j, joy.state.Gamepad.wButtons & button_mask);
button_mask = button_mask * 2; button_mask = button_mask * 2;
} }
@ -406,7 +406,7 @@ void JoypadWindows::process_joypads() {
// on mingw, these constants are not constants // on mingw, these constants are not constants
int count = 6; int count = 6;
int axes[] = { DIJOFS_X, DIJOFS_Y, DIJOFS_Z, DIJOFS_RX, DIJOFS_RY, DIJOFS_RZ }; unsigned int axes[] = { DIJOFS_X, DIJOFS_Y, DIJOFS_Z, DIJOFS_RX, DIJOFS_RY, DIJOFS_RZ };
int values[] = { js.lX, js.lY, js.lZ, js.lRx, js.lRy, js.lRz }; int values[] = { js.lX, js.lY, js.lZ, js.lRx, js.lRy, js.lRz };
for (int j = 0; j < joy->joy_axis.size(); j++) { for (int j = 0; j < joy->joy_axis.size(); j++) {
@ -426,7 +426,11 @@ void JoypadWindows::post_hat(int p_device, DWORD p_dpad) {
int dpad_val = 0; int dpad_val = 0;
if (p_dpad == -1) { // Should be -1 when centered, but according to docs:
// "Some drivers report the centered position of the POV indicator as 65,535. Determine whether the indicator is centered as follows:
// BOOL POVCentered = (LOWORD(dwPOV) == 0xFFFF);"
// https://docs.microsoft.com/en-us/previous-versions/windows/desktop/ee416628(v%3Dvs.85)#remarks
if (LOWORD(p_dpad) == 0xFFFF) {
dpad_val = InputDefault::HAT_MASK_CENTER; dpad_val = InputDefault::HAT_MASK_CENTER;
} }
if (p_dpad == 0) { if (p_dpad == 0) {

View file

@ -94,6 +94,7 @@ static BOOL CALLBACK _MonitorEnumProcSize(HMONITOR hMonitor, HDC hdcMonitor, LPR
return TRUE; return TRUE;
} }
#ifdef DEBUG_ENABLED
static String format_error_message(DWORD id) { static String format_error_message(DWORD id) {
LPWSTR messageBuffer = NULL; LPWSTR messageBuffer = NULL;
@ -106,6 +107,7 @@ static String format_error_message(DWORD id) {
return msg; return msg;
} }
#endif // DEBUG_ENABLED
extern HINSTANCE godot_hinstance; extern HINSTANCE godot_hinstance;
@ -555,6 +557,7 @@ LRESULT OS_Windows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
break; break;
} }
} }
FALLTHROUGH;
case WM_MBUTTONDOWN: case WM_MBUTTONDOWN:
case WM_MBUTTONUP: case WM_MBUTTONUP:
case WM_RBUTTONDOWN: case WM_RBUTTONDOWN:
@ -583,7 +586,6 @@ LRESULT OS_Windows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
case WM_MBUTTONDOWN: { case WM_MBUTTONDOWN: {
mb->set_pressed(true); mb->set_pressed(true);
mb->set_button_index(3); mb->set_button_index(3);
} break; } break;
case WM_MBUTTONUP: { case WM_MBUTTONUP: {
mb->set_pressed(false); mb->set_pressed(false);
@ -598,19 +600,16 @@ LRESULT OS_Windows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
mb->set_button_index(2); mb->set_button_index(2);
} break; } break;
case WM_LBUTTONDBLCLK: { case WM_LBUTTONDBLCLK: {
mb->set_pressed(true); mb->set_pressed(true);
mb->set_button_index(1); mb->set_button_index(1);
mb->set_doubleclick(true); mb->set_doubleclick(true);
} break; } break;
case WM_RBUTTONDBLCLK: { case WM_RBUTTONDBLCLK: {
mb->set_pressed(true); mb->set_pressed(true);
mb->set_button_index(2); mb->set_button_index(2);
mb->set_doubleclick(true); mb->set_doubleclick(true);
} break; } break;
case WM_MBUTTONDBLCLK: { case WM_MBUTTONDBLCLK: {
mb->set_pressed(true); mb->set_pressed(true);
mb->set_button_index(3); mb->set_button_index(3);
mb->set_doubleclick(true); mb->set_doubleclick(true);
@ -1816,11 +1815,11 @@ void OS_Windows::set_window_size(const Size2 p_size) {
// Don't let the mouse leave the window when resizing to a smaller resolution // Don't let the mouse leave the window when resizing to a smaller resolution
if (mouse_mode == MOUSE_MODE_CONFINED) { if (mouse_mode == MOUSE_MODE_CONFINED) {
RECT rect; RECT crect;
GetClientRect(hWnd, &rect); GetClientRect(hWnd, &crect);
ClientToScreen(hWnd, (POINT *)&rect.left); ClientToScreen(hWnd, (POINT *)&crect.left);
ClientToScreen(hWnd, (POINT *)&rect.right); ClientToScreen(hWnd, (POINT *)&crect.right);
ClipCursor(&rect); ClipCursor(&crect);
} }
} }
void OS_Windows::set_window_fullscreen(bool p_enabled) { void OS_Windows::set_window_fullscreen(bool p_enabled) {
@ -2193,6 +2192,8 @@ uint64_t OS_Windows::get_unix_time() const {
FILETIME fep; FILETIME fep;
SystemTimeToFileTime(&ep, &fep); SystemTimeToFileTime(&ep, &fep);
// FIXME: dereferencing type-punned pointer will break strict-aliasing rules (GCC warning)
// https://docs.microsoft.com/en-us/windows/desktop/api/minwinbase/ns-minwinbase-filetime#remarks
return (*(uint64_t *)&ft - *(uint64_t *)&fep) / 10000000; return (*(uint64_t *)&ft - *(uint64_t *)&fep) / 10000000;
}; };
@ -2378,7 +2379,7 @@ void OS_Windows::set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shap
} }
// Finally, create the icon // Finally, create the icon
ICONINFO iconinfo = { 0 }; ICONINFO iconinfo;
iconinfo.fIcon = FALSE; iconinfo.fIcon = FALSE;
iconinfo.xHotspot = p_hotspot.x; iconinfo.xHotspot = p_hotspot.x;
iconinfo.yHotspot = p_hotspot.y; iconinfo.yHotspot = p_hotspot.y;
@ -2531,9 +2532,9 @@ Error OS_Windows::execute(const String &p_path, const List<String> &p_arguments,
if (p_blocking) { if (p_blocking) {
DWORD ret = WaitForSingleObject(pi.pi.hProcess, INFINITE); DWORD ret2 = WaitForSingleObject(pi.pi.hProcess, INFINITE);
if (r_exitcode) if (r_exitcode)
*r_exitcode = ret; *r_exitcode = ret2;
CloseHandle(pi.pi.hProcess); CloseHandle(pi.pi.hProcess);
CloseHandle(pi.pi.hThread); CloseHandle(pi.pi.hThread);

View file

@ -89,7 +89,7 @@ bool PowerWindows::GetPowerInfo_Windows() {
if (pct != 255) { /* 255 == unknown */ if (pct != 255) { /* 255 == unknown */
percent_left = (pct > 100) ? 100 : pct; /* clamp between 0%, 100% */ percent_left = (pct > 100) ? 100 : pct; /* clamp between 0%, 100% */
} }
if (secs != 0xFFFFFFFF) { /* ((DWORD)-1) == unknown */ if (secs != (int)0xFFFFFFFF) { /* ((DWORD)-1) == unknown */
nsecs_left = secs; nsecs_left = secs;
} }
} }

View file

@ -45,7 +45,7 @@ void WindowsTerminalLogger::logv(const char *p_format, va_list p_list, bool p_er
int len = vsnprintf(buf, BUFFER_SIZE, p_format, p_list); int len = vsnprintf(buf, BUFFER_SIZE, p_format, p_list);
if (len <= 0) if (len <= 0)
return; return;
if (len >= BUFFER_SIZE) if ((unsigned int)len >= BUFFER_SIZE)
len = BUFFER_SIZE; // Output is too big, will be truncated len = BUFFER_SIZE; // Output is too big, will be truncated
buf[len] = 0; buf[len] = 0;
@ -154,4 +154,4 @@ void WindowsTerminalLogger::log_error(const char *p_function, const char *p_file
WindowsTerminalLogger::~WindowsTerminalLogger() {} WindowsTerminalLogger::~WindowsTerminalLogger() {}
#endif #endif

View file

@ -33,6 +33,8 @@
#include "core/engine.h" #include "core/engine.h"
#include "scene/resources/texture.h" #include "scene/resources/texture.h"
const float DEFAULT_GIZMO_EXTENTS = 10.0;
void Position2D::_draw_cross() { void Position2D::_draw_cross() {
float extents = get_gizmo_extents(); float extents = get_gizmo_extents();

View file

@ -37,8 +37,6 @@ class Position2D : public Node2D {
GDCLASS(Position2D, Node2D) GDCLASS(Position2D, Node2D)
const float DEFAULT_GIZMO_EXTENTS = 10.0;
void _draw_cross(); void _draw_cross();
protected: protected: