summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Franke <arnfranke@yahoo.com>2021-09-07 23:25:35 -0500
committerAaron Franke <arnfranke@yahoo.com>2021-10-12 00:17:27 -0500
commit7e51e4cb84aeb3c191289752e0e6b92facd8f7f6 (patch)
treee07661aeb47a95dbbce602440099da860e2d0c06
parentf9aec342dcd51d65c5970dd395e3c7a66cac446c (diff)
Fix some LGTM errors of "Multiplication result converted to larger type"
-rw-r--r--core/io/file_access_compressed.cpp2
-rw-r--r--core/io/file_access_zip.cpp2
-rw-r--r--core/io/zip_io.cpp2
-rw-r--r--main/main.cpp10
-rw-r--r--modules/hdr/image_loader_hdr.cpp4
-rw-r--r--modules/minimp3/audio_stream_mp3.cpp2
-rw-r--r--platform/javascript/audio_driver_javascript.cpp5
-rw-r--r--scene/2d/parallax_layer.cpp4
-rw-r--r--scene/3d/gpu_particles_collision_3d.cpp2
-rw-r--r--servers/audio/audio_driver_dummy.cpp2
-rw-r--r--servers/audio/audio_rb_resampler.cpp5
-rw-r--r--servers/rendering/renderer_rd/renderer_storage_rd.cpp8
12 files changed, 25 insertions, 23 deletions
diff --git a/core/io/file_access_compressed.cpp b/core/io/file_access_compressed.cpp
index e54c947340..df631053b8 100644
--- a/core/io/file_access_compressed.cpp
+++ b/core/io/file_access_compressed.cpp
@@ -233,7 +233,7 @@ uint64_t FileAccessCompressed::get_position() const {
if (writing) {
return write_pos;
} else {
- return read_block * block_size + read_pos;
+ return (uint64_t)read_block * block_size + read_pos;
}
}
diff --git a/core/io/file_access_zip.cpp b/core/io/file_access_zip.cpp
index b5c882e9ce..53bf7456e6 100644
--- a/core/io/file_access_zip.cpp
+++ b/core/io/file_access_zip.cpp
@@ -99,7 +99,7 @@ static int godot_testerror(voidpf opaque, voidpf stream) {
}
static voidpf godot_alloc(voidpf opaque, uInt items, uInt size) {
- return memalloc(items * size);
+ return memalloc((size_t)items * size);
}
static void godot_free(voidpf opaque, voidpf address) {
diff --git a/core/io/zip_io.cpp b/core/io/zip_io.cpp
index fb4c76aa7a..24808cc8d6 100644
--- a/core/io/zip_io.cpp
+++ b/core/io/zip_io.cpp
@@ -100,7 +100,7 @@ int zipio_testerror(voidpf opaque, voidpf stream) {
}
voidpf zipio_alloc(voidpf opaque, uInt items, uInt size) {
- voidpf ptr = memalloc(items * size);
+ voidpf ptr = memalloc((size_t)items * size);
memset(ptr, 0, items * size);
return ptr;
}
diff --git a/main/main.cpp b/main/main.cpp
index 5a2a088494..3cc7923cc2 100644
--- a/main/main.cpp
+++ b/main/main.cpp
@@ -2488,17 +2488,17 @@ bool Main::iteration() {
iterating++;
- uint64_t ticks = OS::get_singleton()->get_ticks_usec();
+ const uint64_t ticks = OS::get_singleton()->get_ticks_usec();
Engine::get_singleton()->_frame_ticks = ticks;
main_timer_sync.set_cpu_ticks_usec(ticks);
main_timer_sync.set_fixed_fps(fixed_fps);
- uint64_t ticks_elapsed = ticks - last_ticks;
+ const uint64_t ticks_elapsed = ticks - last_ticks;
- int physics_ticks_per_second = Engine::get_singleton()->get_physics_ticks_per_second();
- float physics_step = 1.0 / physics_ticks_per_second;
+ const int physics_ticks_per_second = Engine::get_singleton()->get_physics_ticks_per_second();
+ const double physics_step = 1.0 / physics_ticks_per_second;
- float time_scale = Engine::get_singleton()->get_time_scale();
+ const double time_scale = Engine::get_singleton()->get_time_scale();
MainFrameTime advance = main_timer_sync.advance(physics_step, physics_ticks_per_second);
double process_step = advance.process_step;
diff --git a/modules/hdr/image_loader_hdr.cpp b/modules/hdr/image_loader_hdr.cpp
index 9d6a399eff..32a31aa764 100644
--- a/modules/hdr/image_loader_hdr.cpp
+++ b/modules/hdr/image_loader_hdr.cpp
@@ -65,7 +65,7 @@ Error ImageLoaderHDR::load_image(Ref<Image> p_image, FileAccess *f, bool p_force
Vector<uint8_t> imgdata;
- imgdata.resize(height * width * sizeof(uint32_t));
+ imgdata.resize(height * width * (int)sizeof(uint32_t));
{
uint8_t *w = imgdata.ptrw();
@@ -75,7 +75,7 @@ Error ImageLoaderHDR::load_image(Ref<Image> p_image, FileAccess *f, bool p_force
if (width < 8 || width >= 32768) {
// Read flat data
- f->get_buffer(ptr, width * height * 4);
+ f->get_buffer(ptr, (uint64_t)width * height * 4);
} else {
// Read RLE-encoded data
diff --git a/modules/minimp3/audio_stream_mp3.cpp b/modules/minimp3/audio_stream_mp3.cpp
index 7b52ef178a..17ce051b67 100644
--- a/modules/minimp3/audio_stream_mp3.cpp
+++ b/modules/minimp3/audio_stream_mp3.cpp
@@ -112,7 +112,7 @@ void AudioStreamPlaybackMP3::seek(float p_time) {
}
frames_mixed = uint32_t(mp3_stream->sample_rate * p_time);
- mp3dec_ex_seek(mp3d, frames_mixed * mp3_stream->channels);
+ mp3dec_ex_seek(mp3d, (uint64_t)frames_mixed * mp3_stream->channels);
}
AudioStreamPlaybackMP3::~AudioStreamPlaybackMP3() {
diff --git a/platform/javascript/audio_driver_javascript.cpp b/platform/javascript/audio_driver_javascript.cpp
index cfe6c69072..626aef3c60 100644
--- a/platform/javascript/audio_driver_javascript.cpp
+++ b/platform/javascript/audio_driver_javascript.cpp
@@ -117,14 +117,15 @@ Error AudioDriverJavaScript::init() {
if (output_rb) {
memdelete_arr(output_rb);
}
- output_rb = memnew_arr(float, buffer_length *channel_count);
+ const size_t array_size = buffer_length * (size_t)channel_count;
+ output_rb = memnew_arr(float, array_size);
if (!output_rb) {
return ERR_OUT_OF_MEMORY;
}
if (input_rb) {
memdelete_arr(input_rb);
}
- input_rb = memnew_arr(float, buffer_length *channel_count);
+ input_rb = memnew_arr(float, array_size);
if (!input_rb) {
return ERR_OUT_OF_MEMORY;
}
diff --git a/scene/2d/parallax_layer.cpp b/scene/2d/parallax_layer.cpp
index 67e35cc7a3..797e2e59cb 100644
--- a/scene/2d/parallax_layer.cpp
+++ b/scene/2d/parallax_layer.cpp
@@ -123,12 +123,12 @@ void ParallaxLayer::set_base_offset_and_scale(const Point2 &p_offset, real_t p_s
Point2 new_ofs = (screen_offset + (p_offset - screen_offset) * motion_scale) + motion_offset * p_scale + orig_offset * p_scale;
if (mirroring.x) {
- double den = mirroring.x * p_scale;
+ real_t den = mirroring.x * p_scale;
new_ofs.x -= den * ceil(new_ofs.x / den);
}
if (mirroring.y) {
- double den = mirroring.y * p_scale;
+ real_t den = mirroring.y * p_scale;
new_ofs.y -= den * ceil(new_ofs.y / den);
}
diff --git a/scene/3d/gpu_particles_collision_3d.cpp b/scene/3d/gpu_particles_collision_3d.cpp
index 4fa34615bf..9127168c58 100644
--- a/scene/3d/gpu_particles_collision_3d.cpp
+++ b/scene/3d/gpu_particles_collision_3d.cpp
@@ -475,7 +475,7 @@ Ref<Image> GPUParticlesCollisionSDF::bake() {
_create_bvh(bvh, face_pos.ptr(), face_pos.size(), faces.ptr(), th);
Vector<uint8_t> data;
- data.resize(sdf_size.z * sdf_size.y * sdf_size.x * sizeof(float));
+ data.resize(sdf_size.z * sdf_size.y * sdf_size.x * (int)sizeof(float));
if (bake_step_function) {
bake_step_function(0, "Baking SDF");
diff --git a/servers/audio/audio_driver_dummy.cpp b/servers/audio/audio_driver_dummy.cpp
index a28dcb1015..47799dce96 100644
--- a/servers/audio/audio_driver_dummy.cpp
+++ b/servers/audio/audio_driver_dummy.cpp
@@ -46,7 +46,7 @@ Error AudioDriverDummy::init() {
int latency = GLOBAL_GET("audio/driver/output_latency");
buffer_frames = closest_power_of_2(latency * mix_rate / 1000);
- samples_in = memnew_arr(int32_t, buffer_frames * channels);
+ samples_in = memnew_arr(int32_t, (size_t)buffer_frames * channels);
thread.start(AudioDriverDummy::thread_func, this);
diff --git a/servers/audio/audio_rb_resampler.cpp b/servers/audio/audio_rb_resampler.cpp
index 3c8a1469cd..d9c442facf 100644
--- a/servers/audio/audio_rb_resampler.cpp
+++ b/servers/audio/audio_rb_resampler.cpp
@@ -176,8 +176,9 @@ Error AudioRBResampler::setup(int p_channels, int p_src_mix_rate, int p_target_m
rb_bits = desired_rb_bits;
rb_len = (1 << rb_bits);
rb_mask = rb_len - 1;
- rb = memnew_arr(float, rb_len *p_channels);
- read_buf = memnew_arr(float, rb_len *p_channels);
+ const size_t array_size = rb_len * (size_t)p_channels;
+ rb = memnew_arr(float, array_size);
+ read_buf = memnew_arr(float, array_size);
}
src_mix_rate = p_src_mix_rate;
diff --git a/servers/rendering/renderer_rd/renderer_storage_rd.cpp b/servers/rendering/renderer_rd/renderer_storage_rd.cpp
index 45d3b3f09f..2ece60e107 100644
--- a/servers/rendering/renderer_rd/renderer_storage_rd.cpp
+++ b/servers/rendering/renderer_rd/renderer_storage_rd.cpp
@@ -3959,7 +3959,7 @@ void RendererStorageRD::_multimesh_make_local(MultiMesh *multimesh) const {
memcpy(w, r, buffer.size());
}
} else {
- memset(w, 0, multimesh->instances * multimesh->stride_cache * sizeof(float));
+ memset(w, 0, (size_t)multimesh->instances * multimesh->stride_cache * sizeof(float));
}
}
uint32_t data_cache_dirty_region_count = (multimesh->instances - 1) / MULTIMESH_DIRTY_REGION_SIZE + 1;
@@ -4372,13 +4372,13 @@ void RendererStorageRD::_update_dirty_multimeshes() {
if (multimesh->data_cache_used_dirty_regions > 32 || multimesh->data_cache_used_dirty_regions > visible_region_count / 2) {
//if there too many dirty regions, or represent the majority of regions, just copy all, else transfer cost piles up too much
- RD::get_singleton()->buffer_update(multimesh->buffer, 0, MIN(visible_region_count * region_size, multimesh->instances * multimesh->stride_cache * sizeof(float)), data);
+ RD::get_singleton()->buffer_update(multimesh->buffer, 0, MIN(visible_region_count * region_size, multimesh->instances * (uint32_t)multimesh->stride_cache * (uint32_t)sizeof(float)), data);
} else {
//not that many regions? update them all
for (uint32_t i = 0; i < visible_region_count; i++) {
if (multimesh->data_cache_dirty_regions[i]) {
- uint64_t offset = i * region_size;
- uint64_t size = multimesh->stride_cache * multimesh->instances * sizeof(float);
+ uint32_t offset = i * region_size;
+ uint32_t size = multimesh->stride_cache * (uint32_t)multimesh->instances * (uint32_t)sizeof(float);
RD::get_singleton()->buffer_update(multimesh->buffer, offset, MIN(region_size, size - offset), &data[i * region_size]);
}
}