Skip to content

Commit

Permalink
Fixing warnings generated by MSVC
Browse files Browse the repository at this point in the history
Fixes #22684.
  • Loading branch information
Dualtagh Murray authored and akien-mga committed Oct 19, 2018
1 parent a3072aa commit b902a2f
Show file tree
Hide file tree
Showing 27 changed files with 84 additions and 75 deletions.
4 changes: 2 additions & 2 deletions core/hash_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ class HashMap {
if (new_hash_table_power == -1)
return;

Element **new_hash_table = memnew_arr(Element *, (1 << new_hash_table_power));
Element **new_hash_table = memnew_arr(Element *, ((uint64_t)1 << new_hash_table_power));
if (!new_hash_table) {

ERR_PRINT("Out of Memory");
Expand Down Expand Up @@ -230,7 +230,7 @@ class HashMap {
if (!p_t.hash_table || p_t.hash_table_power == 0)
return; /* not copying from empty table */

hash_table = memnew_arr(Element *, 1 << p_t.hash_table_power);
hash_table = memnew_arr(Element *, (uint64_t)1 << p_t.hash_table_power);
hash_table_power = p_t.hash_table_power;
elements = p_t.elements;

Expand Down
4 changes: 4 additions & 0 deletions core/io/logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@
#endif
#endif

#if defined(MINGW_ENABLED) || defined(_MSC_VER)
#define sprintf sprintf_s
#endif

bool Logger::should_log(bool p_err) {
return (!p_err || _print_error_enabled) && (p_err || _print_line_enabled);
}
Expand Down
2 changes: 1 addition & 1 deletion core/io/resource_format_binary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1309,7 +1309,7 @@ void ResourceFormatSaverBinaryInstance::write_variant(FileAccess *f, const Varia
case Variant::INT: {

int64_t val = p_property;
if (val > 0x7FFFFFFF || val < -0x80000000) {
if (val > 0x7FFFFFFF || val < -(int64_t)0x80000000) {
f->store_32(VARIANT_INT64);
f->store_64(val);

Expand Down
2 changes: 1 addition & 1 deletion core/ustring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
#endif

#if defined(MINGW_ENABLED) || defined(_MSC_VER)
#define snprintf _snprintf
#define snprintf _snprintf_s
#endif

#define MAX_DIGITS 6
Expand Down
5 changes: 5 additions & 0 deletions drivers/gles2/rasterizer_gles2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@
#include <EGL/eglext.h>
#endif

#if defined(MINGW_ENABLED) || defined(_MSC_VER)
#define strcpy strcpy_s
#endif

#ifndef IPHONE_ENABLED
static void GLAPIENTRY _gl_debug_print(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *message, const GLvoid *userParam) {

Expand All @@ -84,6 +88,7 @@ static void GLAPIENTRY _gl_debug_print(GLenum source, GLenum type, GLuint id, GL
return; //these are ultimately annoying, so removing for now

char debSource[256], debType[256], debSev[256];

if (source == _EXT_DEBUG_SOURCE_API_ARB)
strcpy(debSource, "OpenGL");
else if (source == _EXT_DEBUG_SOURCE_WINDOW_SYSTEM_ARB)
Expand Down
4 changes: 4 additions & 0 deletions drivers/gles3/rasterizer_gles3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ RasterizerScene *RasterizerGLES3::get_scene() {
#define _EXT_DEBUG_SEVERITY_LOW_ARB 0x9148
#define _EXT_DEBUG_OUTPUT 0x92E0

#if defined(MINGW_ENABLED) || defined(_MSC_VER)
#define strcpy strcpy_s
#endif

#ifdef GLAD_ENABLED
// Restricting to GLAD as only used in initialize() with GLAD_GL_ARB_debug_output
#if (defined WINDOWS_ENABLED) && !(defined UWP_ENABLED)
Expand Down
11 changes: 4 additions & 7 deletions drivers/gles3/rasterizer_scene_gles3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1246,14 +1246,11 @@ bool RasterizerSceneGLES3::_setup_material(RasterizerStorageGLES3::Material *p_m
case ShaderLanguage::TYPE_SAMPLER3D: {

target = GL_TEXTURE_3D;
tex = storage->resources.white_tex_3d;

switch (texture_hints[i]) {

// TODO
default: {
tex = storage->resources.white_tex_3d;
} break;
}
//switch (texture_hints[i]) {
// TODO
//}

} break;

Expand Down
2 changes: 1 addition & 1 deletion drivers/rtaudio/audio_driver_rtaudio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ Error AudioDriverRtAudio::init() {
active = true;

break;
} catch (RtAudioError &e) {
} catch (RtAudioError) {
// try with less channels
ERR_PRINT("Unable to open audio, retrying with fewer channels...");

Expand Down
4 changes: 2 additions & 2 deletions drivers/windows/file_access_windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ Error FileAccessWindows::_open(const String &p_path, int p_mode_flags) {
path = path + ".tmp";
}

f = _wfopen(path.c_str(), mode_string);
_wfopen_s(&f, path.c_str(), mode_string);

if (f == NULL) {
last_error = ERR_FILE_CANT_OPEN;
Expand Down Expand Up @@ -278,7 +278,7 @@ bool FileAccessWindows::file_exists(const String &p_name) {
FILE *g;
//printf("opening file %s\n", p_fname.c_str());
String filename = fix_path(p_name);
g = _wfopen(filename.c_str(), L"rb");
_wfopen_s(&g, filename.c_str(), L"rb");
if (g == NULL) {

return false;
Expand Down
12 changes: 0 additions & 12 deletions editor/plugins/camera_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,6 @@

#include "spatial_editor_plugin.h"

void CameraEditor::_notification(int p_what) {

switch (p_what) {

/* case NOTIFICATION_PROCESS: {
if (preview->is_pressed() && node)
node->call("make_current");
} break;*/
}
}
void CameraEditor::_node_removed(Node *p_node) {

if (p_node == node) {
Expand Down
1 change: 0 additions & 1 deletion editor/plugins/camera_editor_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ class CameraEditor : public Control {
void _pressed();

protected:
void _notification(int p_what);
void _node_removed(Node *p_node);
static void _bind_methods();

Expand Down
3 changes: 1 addition & 2 deletions editor/spatial_editor_gizmos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3454,10 +3454,9 @@ void CollisionShapeSpatialGizmoPlugin::redraw(EditorSpatialGizmo *p_gizmo) {

if (points.size() > 3) {

QuickHull qh;
Vector<Vector3> varr = Variant(points);
Geometry::MeshData md;
Error err = qh.build(varr, md);
Error err = QuickHull::build(varr, md);
if (err == OK) {
Vector<Vector3> points;
points.resize(md.edges.size() * 2);
Expand Down
4 changes: 4 additions & 0 deletions modules/websocket/lws_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
#include "core/io/stream_peer_ssl.h"
#include "tls/mbedtls/wrapper/include/openssl/ssl.h"

#if defined(MINGW_ENABLED) || defined(_MSC_VER)
#define strncpy strncpy_s
#endif

Error LWSClient::connect_to_host(String p_host, String p_path, uint16_t p_port, bool p_ssl, PoolVector<String> p_protocols) {

ERR_FAIL_COND_V(context != NULL, FAILED);
Expand Down
2 changes: 1 addition & 1 deletion modules/websocket/websocket_multiplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ void WebSocketMultiplayerPeer::_process_multiplayer(Ref<WebSocketPeer> p_peer, u
} else if (to < 0) {

// All but one, for us if not excluded
if (_peer_id != -p_peer_id)
if (_peer_id != -(int32_t)p_peer_id)
_store_pkt(from, to, in_buffer, data_size);

} else {
Expand Down
24 changes: 12 additions & 12 deletions platform/windows/context_gl_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,18 +91,18 @@ Error ContextGL_Win::initialize() {
PFD_DRAW_TO_WINDOW | // Format Must Support Window
PFD_SUPPORT_OPENGL | // Format Must Support OpenGL
PFD_DOUBLEBUFFER,
PFD_TYPE_RGBA,
OS::get_singleton()->is_layered_allowed() ? 32 : 24,
0, 0, 0, 0, 0, 0, // Color Bits Ignored
OS::get_singleton()->is_layered_allowed() ? 8 : 0, // Alpha Buffer
0, // Shift Bit Ignored
0, // No Accumulation Buffer
0, 0, 0, 0, // Accumulation Bits Ignored
24, // 24Bit Z-Buffer (Depth Buffer)
0, // No Stencil Buffer
0, // No Auxiliary Buffer
PFD_MAIN_PLANE, // Main Drawing Layer
0, // Reserved
(BYTE)PFD_TYPE_RGBA,
OS::get_singleton()->is_layered_allowed() ? (BYTE)32 : (BYTE)24,
(BYTE)0, (BYTE)0, (BYTE)0, (BYTE)0, (BYTE)0, (BYTE)0, // Color Bits Ignored
OS::get_singleton()->is_layered_allowed() ? (BYTE)8 : (BYTE)0, // Alpha Buffer
(BYTE)0, // Shift Bit Ignored
(BYTE)0, // No Accumulation Buffer
(BYTE)0, (BYTE)0, (BYTE)0, (BYTE)0, // Accumulation Bits Ignored
(BYTE)24, // 24Bit Z-Buffer (Depth Buffer)
(BYTE)0, // No Stencil Buffer
(BYTE)0, // No Auxiliary Buffer
(BYTE)PFD_MAIN_PLANE, // Main Drawing Layer
(BYTE)0, // Reserved
0, 0, 0 // Layer Masks Ignored
};

Expand Down
2 changes: 1 addition & 1 deletion platform/windows/joypad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ bool JoypadWindows::setup_dinput_joypad(const DIDEVICEINSTANCE *instance) {

const GUID &guid = instance->guidProduct;
char uid[128];
sprintf(uid, "%08lx%04hx%04hx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx",
sprintf_s(uid, "%08lx%04hx%04hx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx",
__builtin_bswap32(guid.Data1), guid.Data2, guid.Data3,
guid.Data4[0], guid.Data4[1], guid.Data4[2], guid.Data4[3],
guid.Data4[4], guid.Data4[5], guid.Data4[6], guid.Data4[7]);
Expand Down
21 changes: 19 additions & 2 deletions platform/windows/os_windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1204,7 +1204,14 @@ Error OS_Windows::initialize(const VideoMode &p_desired, int p_video_driver, int

AdjustWindowRectEx(&WindowRect, dwStyle, FALSE, dwExStyle);

char *windowid = getenv("GODOT_WINDOWID");
char *windowid;
#ifdef MINGW_ENABLED
windowid = getenv("GODOT_WINDOWID");
#else
size_t len;
_dupenv_s(&windowid, &len, "GODOT_WINDOWID");
#endif

if (windowid) {

// strtoull on mingw
Expand All @@ -1213,6 +1220,7 @@ Error OS_Windows::initialize(const VideoMode &p_desired, int p_video_driver, int
#else
hWnd = (HWND)_strtoui64(windowid, NULL, 0);
#endif
free(windowid);
SetLastError(0);
user_proc = (WNDPROC)GetWindowLongPtr(hWnd, GWLP_WNDPROC);
SetWindowLongPtr(hWnd, GWLP_WNDPROC, (LONG_PTR)(WNDPROC)::WndProc);
Expand Down Expand Up @@ -2546,7 +2554,16 @@ void OS_Windows::set_icon(const Ref<Image> &p_icon) {

bool OS_Windows::has_environment(const String &p_var) const {

#ifdef MINGW_ENABLED
return _wgetenv(p_var.c_str()) != NULL;
#else
wchar_t *env;
size_t len;
_wdupenv_s(&env, &len, p_var.c_str());
const bool has_env = env != NULL;
free(env);
return has_env;
#endif
};

String OS_Windows::get_environment(const String &p_var) const {
Expand Down Expand Up @@ -2926,7 +2943,7 @@ bool OS_Windows::is_disable_crash_handler() const {
Error OS_Windows::move_to_trash(const String &p_path) {
SHFILEOPSTRUCTW sf;
WCHAR *from = new WCHAR[p_path.length() + 2];
wcscpy(from, p_path.c_str());
wcscpy_s(from, p_path.length() + 1, p_path.c_str());
from[p_path.length() + 1] = 0;

sf.hwnd = hWnd;
Expand Down
6 changes: 0 additions & 6 deletions scene/2d/node_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,12 +204,6 @@ Size2 Node2D::get_scale() const {
return _scale;
}

void Node2D::_notification(int p_what) {

switch (p_what) {
}
}

Transform2D Node2D::get_transform() const {

return _mat;
Expand Down
2 changes: 0 additions & 2 deletions scene/2d/node_2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ class Node2D : public CanvasItem {
void _update_xform_values();

protected:
void _notification(int p_what);

static void _bind_methods();

public:
Expand Down
2 changes: 1 addition & 1 deletion scene/2d/tile_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ void TileMap::update_dirty_quadrants() {

if (quadrant_order_dirty) {

int index = -0x80000000; //always must be drawn below children
int index = -(int64_t)0x80000000; //always must be drawn below children
for (Map<PosKey, Quadrant>::Element *E = quadrant_map.front(); E; E = E->next()) {

Quadrant &q = E->get();
Expand Down
2 changes: 1 addition & 1 deletion scene/3d/audio_stream_player_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ void AudioStreamPlayer3D::_notification(int p_what) {

//float dist_att_db = -20 * Math::log(dist + 0.00001); //logarithmic attenuation, like in real life

float center_val[3] = { 0.5, 0.25, 0.16666 };
float center_val[3] = { 0.5f, 0.25f, 0.16666f };
AudioFrame center_frame(center_val[vol_index_max - 1], center_val[vol_index_max - 1]);

if (attenuation < 1.0) {
Expand Down
6 changes: 3 additions & 3 deletions scene/3d/voxel_light_baker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1619,7 +1619,7 @@ Vector3 VoxelLightBaker::_compute_pixel_light_at_pos(const Vector3 &p_pos, const
Vector3(-0.700629, -0.509037, 0.5),
Vector3(0.267617, -0.823639, 0.5)
};
static const float weights[6] = { 0.25, 0.15, 0.15, 0.15, 0.15, 0.15 };
static const float weights[6] = { 0.25f, 0.15f, 0.15f, 0.15f, 0.15f, 0.15f };
//
cone_dirs = dirs;
cone_dir_count = 6;
Expand All @@ -1641,7 +1641,7 @@ Vector3 VoxelLightBaker::_compute_pixel_light_at_pos(const Vector3 &p_pos, const
Vector3(0.19124006749743122, 0.39355745585016605, 0.8991883926788214),
Vector3(0.19124006749743122, -0.39355745585016605, 0.8991883926788214),
};
static const float weights[10] = { 0.08571, 0.08571, 0.08571, 0.08571, 0.08571, 0.08571, 0.08571, 0.133333, 0.133333, 0.13333 };
static const float weights[10] = { 0.08571f, 0.08571f, 0.08571f, 0.08571f, 0.08571f, 0.08571f, 0.08571f, 0.133333f, 0.133333f, 0.13333f };
cone_dirs = dirs;
cone_dir_count = 10;
cone_aperture = 0.404; // tan(angle) 45 degrees
Expand Down Expand Up @@ -1875,7 +1875,7 @@ Error VoxelLightBaker::make_lightmap(const Transform &p_xform, Ref<Mesh> &p_mesh
if (bake_mode == BAKE_MODE_RAY_TRACE) {
//blur
//gauss kernel, 7 step sigma 2
static const float gauss_kernel[4] = { 0.214607, 0.189879, 0.131514, 0.071303 };
static const float gauss_kernel[4] = { 0.214607f, 0.189879f, 0.131514f, 0.071303f };
//horizontal pass
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
Expand Down
3 changes: 1 addition & 2 deletions scene/resources/convex_polygon_shape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,9 @@ Vector<Vector3> ConvexPolygonShape::_gen_debug_mesh_lines() {

if (points.size() > 3) {

QuickHull qh;
Vector<Vector3> varr = Variant(points);
Geometry::MeshData md;
Error err = qh.build(varr, md);
Error err = QuickHull::build(varr, md);
if (err == OK) {
Vector<Vector3> lines;
lines.resize(md.edges.size() * 2);
Expand Down
4 changes: 2 additions & 2 deletions scene/resources/dynamic_font.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,10 @@ Error DynamicFontAtSize::_load() {

if (FT_HAS_COLOR(face)) {
int best_match = 0;
int diff = ABS(id.size - face->available_sizes[0].width);
int diff = ABS(id.size - ((int64_t)face->available_sizes[0].width));
scale_color_font = float(id.size) / face->available_sizes[0].width;
for (int i = 1; i < face->num_fixed_sizes; i++) {
int ndiff = ABS(id.size - face->available_sizes[i].width);
int ndiff = ABS(id.size - ((int64_t)face->available_sizes[i].width));
if (ndiff < diff) {
best_match = i;
diff = ndiff;
Expand Down
24 changes: 12 additions & 12 deletions servers/audio/effects/reverb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,22 @@

const float Reverb::comb_tunings[MAX_COMBS] = {
//freeverb comb tunings
0.025306122448979593,
0.026938775510204082,
0.028956916099773241,
0.03074829931972789,
0.032244897959183672,
0.03380952380952381,
0.035306122448979592,
0.036666666666666667
0.025306122448979593f,
0.026938775510204082f,
0.028956916099773241f,
0.03074829931972789f,
0.032244897959183672f,
0.03380952380952381f,
0.035306122448979592f,
0.036666666666666667f
};

const float Reverb::allpass_tunings[MAX_ALLPASS] = {
//freeverb allpass tunings
0.0051020408163265302,
0.007732426303854875,
0.01,
0.012607709750566893
0.0051020408163265302f,
0.007732426303854875f,
0.01f,
0.012607709750566893f
};

void Reverb::process(float *p_src, float *p_dst, int p_frames) {
Expand Down
Loading

0 comments on commit b902a2f

Please sign in to comment.