Skip to content

Commit

Permalink
Fix warning that index can't be < 0 due to being unsigned
Browse files Browse the repository at this point in the history
  • Loading branch information
Zylann committed Nov 3, 2023
1 parent b39e61f commit 208695b
Show file tree
Hide file tree
Showing 12 changed files with 35 additions and 35 deletions.
4 changes: 2 additions & 2 deletions generators/graph/node_type_db.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ bool NodeTypeDB::try_get_type_id_from_name(const String &name, VoxelGraphFunctio
}

bool NodeTypeDB::try_get_param_index_from_name(uint32_t type_id, const String &name, uint32_t &out_param_index) const {
ERR_FAIL_INDEX_V(type_id, _types.size(), false);
ZN_ASSERT_RETURN_V(type_id < _types.size(), false);
const NodeType &t = _types[type_id];
auto it = t.param_name_to_index.find(name);
if (it == t.param_name_to_index.end()) {
Expand All @@ -200,7 +200,7 @@ bool NodeTypeDB::try_get_param_index_from_name(uint32_t type_id, const String &n
}

bool NodeTypeDB::try_get_input_index_from_name(uint32_t type_id, const String &name, uint32_t &out_input_index) const {
ERR_FAIL_INDEX_V(type_id, _types.size(), false);
ZN_ASSERT_RETURN_V(type_id < _types.size(), false);
const NodeType &t = _types[type_id];
auto it = t.input_name_to_index.find(name);
if (it == t.input_name_to_index.end()) {
Expand Down
20 changes: 10 additions & 10 deletions generators/graph/voxel_graph_function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -452,10 +452,10 @@ uint32_t VoxelGraphFunction::find_node_by_name(StringName p_name) const {
return _graph.find_node_by_name(p_name);
}

void VoxelGraphFunction::set_node_param(uint32_t node_id, uint32_t param_index, Variant value) {
void VoxelGraphFunction::set_node_param(uint32_t node_id, int param_index, Variant value) {
ProgramGraph::Node *node = _graph.try_get_node(node_id);
ERR_FAIL_COND(node == nullptr);
ERR_FAIL_INDEX(param_index, node->params.size());
ERR_FAIL_INDEX(param_index, static_cast<int>(node->params.size()));

if (node->params[param_index] != value) {
if (node->type_id == VoxelGraphFunction::NODE_FUNCTION && param_index == 0) {
Expand Down Expand Up @@ -550,24 +550,24 @@ void VoxelGraphFunction::set_expression_node_inputs(uint32_t node_id, PackedStri
}
}

Variant VoxelGraphFunction::get_node_param(uint32_t node_id, uint32_t param_index) const {
Variant VoxelGraphFunction::get_node_param(uint32_t node_id, int param_index) const {
const ProgramGraph::Node *node = _graph.try_get_node(node_id);
ERR_FAIL_COND_V(node == nullptr, Variant());
ERR_FAIL_INDEX_V(param_index, node->params.size(), Variant());
ERR_FAIL_INDEX_V(param_index, static_cast<int>(node->params.size()), Variant());
return node->params[param_index];
}

Variant VoxelGraphFunction::get_node_default_input(uint32_t node_id, uint32_t input_index) const {
Variant VoxelGraphFunction::get_node_default_input(uint32_t node_id, int input_index) const {
const ProgramGraph::Node *node = _graph.try_get_node(node_id);
ERR_FAIL_COND_V(node == nullptr, Variant());
ERR_FAIL_INDEX_V(input_index, node->default_inputs.size(), Variant());
ERR_FAIL_INDEX_V(input_index, static_cast<int>(node->default_inputs.size()), Variant());
return node->default_inputs[input_index];
}

void VoxelGraphFunction::set_node_default_input(uint32_t node_id, uint32_t input_index, Variant value) {
void VoxelGraphFunction::set_node_default_input(uint32_t node_id, int input_index, Variant value) {
ProgramGraph::Node *node = _graph.try_get_node(node_id);
ERR_FAIL_COND(node == nullptr);
ERR_FAIL_INDEX(input_index, node->default_inputs.size());
ERR_FAIL_INDEX(input_index, static_cast<int>(node->default_inputs.size()));
Variant &defval = node->default_inputs[input_index];
if (defval != value) {
// node->autoconnect_default_inputs = false;
Expand Down Expand Up @@ -1007,11 +1007,11 @@ static bool load_graph_from_variant_data(ProgramGraph &graph, Dictionary data, S
}
uint32_t param_index;
if (type_db.try_get_param_index_from_name(type_id, param_name, param_index)) {
ERR_CONTINUE(param_index < 0 || param_index >= node->params.size());
ZN_ASSERT_CONTINUE(param_index < node->params.size());
node->params[param_index] = node_data[param_key];
}
if (type_db.try_get_input_index_from_name(type_id, param_name, param_index)) {
ERR_CONTINUE(param_index < 0 || param_index >= node->default_inputs.size());
ZN_ASSERT_CONTINUE(param_index < node->default_inputs.size());
node->default_inputs[param_index] = node_data[param_key];
}
if (function.is_valid()) {
Expand Down
8 changes: 4 additions & 4 deletions generators/graph/voxel_graph_function.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,15 @@ class VoxelGraphFunction : public Resource {
StringName get_node_name(uint32_t node_id) const;
uint32_t find_node_by_name(StringName p_name) const;

Variant get_node_param(uint32_t node_id, uint32_t param_index) const;
void set_node_param(uint32_t node_id, uint32_t param_index, Variant value);
Variant get_node_param(uint32_t node_id, int param_index) const;
void set_node_param(uint32_t node_id, int param_index, Variant value);

static bool get_expression_variables(std::string_view code, std::vector<std::string_view> &vars);
void get_expression_node_inputs(uint32_t node_id, std::vector<std::string> &out_names) const;
void set_expression_node_inputs(uint32_t node_id, PackedStringArray input_names);

Variant get_node_default_input(uint32_t node_id, uint32_t input_index) const;
void set_node_default_input(uint32_t node_id, uint32_t input_index, Variant value);
Variant get_node_default_input(uint32_t node_id, int input_index) const;
void set_node_default_input(uint32_t node_id, int input_index, Variant value);

bool get_node_default_inputs_autoconnect(uint32_t node_id) const;
void set_node_default_inputs_autoconnect(uint32_t node_id, bool enabled);
Expand Down
2 changes: 1 addition & 1 deletion generators/voxel_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ int VoxelGenerator::get_used_channels_mask() const {
VoxelSingleValue VoxelGenerator::generate_single(Vector3i pos, unsigned int channel) {
VoxelSingleValue v;
v.i = 0;
ZN_ASSERT_RETURN_V(channel >= 0 && channel < VoxelBufferInternal::MAX_CHANNELS, v);
ZN_ASSERT_RETURN_V(channel < VoxelBufferInternal::MAX_CHANNELS, v);
// Default slow implementation
// TODO Optimize: a small part of the slowness is caused by the allocator.
// It is not a good use of `VoxelMemoryPool` for such a small size called so often.
Expand Down
2 changes: 1 addition & 1 deletion meshers/blocky/voxel_blocky_library_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void VoxelBlockyLibraryBase::_b_bake() {
}

Ref<Material> VoxelBlockyLibraryBase::get_material_by_index(unsigned int index) const {
ERR_FAIL_INDEX_V(index, _indexed_materials.size(), Ref<Material>());
ZN_ASSERT_RETURN_V(index < _indexed_materials.size(), Ref<Material>());
return _indexed_materials[index];
}

Expand Down
2 changes: 1 addition & 1 deletion meshers/cubes/voxel_mesher_cubes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1033,7 +1033,7 @@ void VoxelMesherCubes::set_material_by_index(Materials id, Ref<Material> materia
}

Ref<Material> VoxelMesherCubes::get_material_by_index(unsigned int i) const {
ERR_FAIL_INDEX_V(i, _materials.size(), Ref<Material>());
ZN_ASSERT_RETURN_V(i < _materials.size(), Ref<Material>());
return _materials[i];
}

Expand Down
8 changes: 4 additions & 4 deletions storage/voxel_buffer_gd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,19 @@ void VoxelBuffer::copy_channel_from_area(
_buffer->copy_from(other->get_buffer(), src_min, src_max, dst_min, channel);
}

void VoxelBuffer::fill(uint64_t defval, unsigned int channel_index) {
void VoxelBuffer::fill(uint64_t defval, int channel_index) {
ZN_DSTACK();
ERR_FAIL_INDEX(channel_index, MAX_CHANNELS);
_buffer->fill(defval, channel_index);
}

void VoxelBuffer::fill_f(real_t value, unsigned int channel) {
void VoxelBuffer::fill_f(real_t value, int channel) {
ZN_DSTACK();
ERR_FAIL_INDEX(channel, MAX_CHANNELS);
_buffer->fill_f(value, channel);
}

bool VoxelBuffer::is_uniform(unsigned int channel_index) const {
bool VoxelBuffer::is_uniform(int channel_index) const {
ERR_FAIL_INDEX_V(channel_index, MAX_CHANNELS, true);
return _buffer->is_uniform(channel_index);
}
Expand All @@ -80,7 +80,7 @@ void VoxelBuffer::compress_uniform_channels() {
_buffer->compress_uniform_channels();
}

VoxelBuffer::Compression VoxelBuffer::get_channel_compression(unsigned int channel_index) const {
VoxelBuffer::Compression VoxelBuffer::get_channel_compression(int channel_index) const {
ERR_FAIL_INDEX_V(channel_index, MAX_CHANNELS, VoxelBuffer::COMPRESSION_NONE);
return VoxelBuffer::Compression(_buffer->get_channel_compression(channel_index));
}
Expand Down
8 changes: 4 additions & 4 deletions storage/voxel_buffer_gd.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,16 +113,16 @@ class VoxelBuffer : public RefCounted {
void copy_channel_from_area(
Ref<VoxelBuffer> other, Vector3i src_min, Vector3i src_max, Vector3i dst_min, unsigned int channel);

void fill(uint64_t defval, unsigned int channel_index = 0);
void fill_f(real_t value, unsigned int channel = 0);
void fill(uint64_t defval, int channel_index = 0);
void fill_f(real_t value, int channel = 0);
void fill_area(uint64_t defval, Vector3i min, Vector3i max, unsigned int channel_index) {
_buffer->fill_area(defval, min, max, channel_index);
}

bool is_uniform(unsigned int channel_index) const;
bool is_uniform(int channel_index) const;

void compress_uniform_channels();
Compression get_channel_compression(unsigned int channel_index) const;
Compression get_channel_compression(int channel_index) const;

void downscale_to(Ref<VoxelBuffer> dst, Vector3i src_min, Vector3i src_max, Vector3i dst_min) const;

Expand Down
4 changes: 2 additions & 2 deletions streams/region/voxel_stream_region_files.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ static bool u32_from_json_variant(const Variant &v, uint32_t &i) {
static bool depth_from_json_variant(Variant &v, VoxelBufferInternal::Depth &d) {
uint8_t n;
ERR_FAIL_COND_V(!u8_from_json_variant(v, n), false);
ERR_FAIL_INDEX_V(n, VoxelBufferInternal::DEPTH_COUNT, false);
ZN_ASSERT_RETURN_V(n < VoxelBufferInternal::DEPTH_COUNT, false);
d = (VoxelBufferInternal::Depth)n;
return true;
}
Expand Down Expand Up @@ -444,7 +444,7 @@ VoxelStreamRegionFiles::CachedRegion *VoxelStreamRegionFiles::open_region(
const Vector3i region_pos, unsigned int lod, bool create_if_not_found) {
ZN_PROFILE_SCOPE();
ERR_FAIL_COND_V(!_meta_loaded, nullptr);
ERR_FAIL_COND_V(lod < 0, nullptr);
ZN_ASSERT_RETURN_V(lod < constants::MAX_LOD, nullptr);

CachedRegion *cached_region = get_region_from_cache(region_pos, lod);
if (cached_region != nullptr) {
Expand Down
4 changes: 2 additions & 2 deletions streams/voxel_block_serializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -494,8 +494,8 @@ bool migrate_v2_to_v3(Span<const uint8_t> p_data, std::vector<uint8_t> &dst) {
const uint8_t compression_value = fmt & 0xf;
const uint8_t depth_value = (fmt >> 4) & 0xf;

ERR_FAIL_INDEX_V(compression_value, 2, false);
ERR_FAIL_INDEX_V(depth_value, 4, false);
ZN_ASSERT_RETURN_V(compression_value < 2, false);
ZN_ASSERT_RETURN_V(depth_value < 4, false);

const unsigned int voxel_size = 1 << depth_value;

Expand Down
6 changes: 3 additions & 3 deletions terrain/instancing/voxel_instancer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1767,7 +1767,7 @@ void VoxelInstancer::on_area_edited(Box3i p_voxel_box) {
void VoxelInstancer::on_body_removed(
Vector3i data_block_position, unsigned int render_block_index, unsigned int instance_index) {
Block &block = *_blocks[render_block_index];
ERR_FAIL_INDEX(instance_index, block.bodies.size());
ZN_ASSERT_RETURN(instance_index < block.bodies.size());

if (block.multimesh_instance.is_valid()) {
// Remove the multimesh instance
Expand Down Expand Up @@ -1804,7 +1804,7 @@ void VoxelInstancer::on_body_removed(
void VoxelInstancer::on_scene_instance_removed(
Vector3i data_block_position, unsigned int render_block_index, unsigned int instance_index) {
Block &block = *_blocks[render_block_index];
ERR_FAIL_INDEX(instance_index, block.scene_instances.size());
ZN_ASSERT_RETURN(instance_index < block.scene_instances.size());

// Unregister the scene instance
unsigned int instance_count = block.scene_instances.size();
Expand Down Expand Up @@ -1845,7 +1845,7 @@ void VoxelInstancer::set_mesh_lod_distance(float p_lod_distance) {
}

int VoxelInstancer::get_library_item_id_from_render_block_index(unsigned int render_block_index) const {
ERR_FAIL_INDEX_V(render_block_index, _blocks.size(), -1);
ZN_ASSERT_RETURN_V(render_block_index < _blocks.size(), -1);
Block &block = *_blocks[render_block_index];
return block.layer_id;
}
Expand Down
2 changes: 1 addition & 1 deletion terrain/variable_lod/lod_octree.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class LodOctree {

const Node *get_child(const Node *node, unsigned int i) const {
ERR_FAIL_COND_V(node == nullptr, nullptr);
ERR_FAIL_INDEX_V(i, 8, nullptr);
ZN_ASSERT_RETURN_V(i < 8, nullptr);
return get_node(node->first_child + i);
}

Expand Down

0 comments on commit 208695b

Please sign in to comment.