-
-
Notifications
You must be signed in to change notification settings - Fork 19.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bunch of missing else
statements and general logic
#7878
Conversation
Please review the changes, I added some comments on some if statements too. |
@@ -148,7 +148,7 @@ class GetClassAndNamespace { | |||
|
|||
idx+=2; | |||
break; | |||
} if (code[idx]=='\n') { | |||
} else if (code[idx]=='\n') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess the previous if
needs an else
too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
@@ -329,7 +329,7 @@ PropertyInfo VisualScriptBuiltinFunc::get_input_value_port_info(int p_idx) const | |||
case LOGIC_CLAMP: { | |||
if (p_idx==0) | |||
return PropertyInfo(Variant::REAL,"a"); | |||
else if (p_idx==0) | |||
else if (p_idx==0) // is it ok to test p_idx == 0 twice? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That looks like a bug.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc @reduz.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I can tell, the second one should be p_idx==1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, it should be p_idx==1
.
@@ -2806,6 +2806,7 @@ void RasterizerSceneGLES3::_copy_to_front_buffer(Environment *env) { | |||
//no environment, simply convert from linear to srgb | |||
storage->shaders.copy.set_conditional(CopyShaderGLES3::LINEAR_TO_SRGB,true); | |||
} else { | |||
/* Why are both statements equal? */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably a bug. Would be worth checking the similar code in the gles2 rasterizer if it exists (some code was copy pasted and adapted, could have typos), or the git blame.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc @reduz
@@ -314,7 +314,7 @@ void ItemList::move_item(int p_item,int p_to_pos) { | |||
|
|||
if (current<0) { | |||
//do none | |||
} if (p_item==current) { | |||
} else if (p_item==current) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That actually changes the logic, but I guess the previous behaviour could be considered a bug.
@@ -181,7 +181,7 @@ void RayShapeSW::get_supports(const Vector3& p_normal,int p_max,Vector3 *r_suppo | |||
r_amount=2; | |||
r_supports[0]=Vector3(0,0,0); | |||
r_supports[1]=Vector3(0,0,length); | |||
} if (p_normal.z>0) { | |||
} else if (p_normal.z>0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That also changes/fixes a probable logic bug (if p_normal.z
was positive, the previous case would always be overridden.
@@ -353,6 +353,7 @@ void TextureRegionEditor::_region_input(const InputEvent& p_input) | |||
undo_redo->add_undo_method(atlas_tex.ptr(),"set_region",rect_prev); | |||
} | |||
else if(node_patch9){ | |||
/* Is this intentional? */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a bug, cc @MarianoGnu.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The changes look good to me, the various comments are also relevant and should likely be discussed and fixed before merging.
else
statements.else
statements and general logic
I added some more, please have a look at them. :) BTW, I am using PVS-Studio static analyzer free. There is no way in hell I could spot these on my own, no matter how meticulous would I be. There is about a thousand more or less, entry logs as a "potential" bugs. |
@@ -3065,7 +3065,7 @@ bool Variant::hash_compare(const Variant& p_variant) const { | |||
return false; | |||
|
|||
for(int i = 0; i < l.size(); ++i) { | |||
if(! l[0].hash_compare(r[0])) | |||
if(! l[i].hash_compare(r[i])) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure about this! Do both indices need to be counter i
? or just one of them? Are we comparing if the two arrays are equal (it seems to me it is)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CC @hpvb.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct, that is broken. Bad @hpvb, bad.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@RebelliousX Line 2956 has the same bug. I can make a PR for this, or you can roll it in this one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hpvb Done ;)
@@ -982,7 +982,7 @@ void make_default_theme(bool p_hidpi,Ref<Font> p_font) { | |||
Ref<BitmapFont> default_font; | |||
if (p_font.is_valid()) { | |||
default_font=p_font; | |||
} if (p_hidpi) { | |||
} else if (p_hidpi) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the bug is elsewhere. With this change the check for p_font.is_valid() becomes useless. If we don't need it remove the whole case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No I think the change is fine. As I understand it, the behaviour of this method is (at least it was until now and the change keeps it):
- If p_font is a valid font, use it
- If it isn't, use the default font for either hidpi (if p_hidpi) or lodpi
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And indeed that's the expected logic:
godot/scene/register_scene_types.cpp
Lines 284 to 300 in de0045c
String font_path = GLOBAL_DEF("gui/theme/custom_font",""); | |
GlobalConfig::get_singleton()->set_custom_property_info("gui/theme/custom_font",PropertyInfo(Variant::STRING,"gui/theme/custom_font",PROPERTY_HINT_FILE,"*.tres,*.res,*.fnt",PROPERTY_USAGE_DEFAULT|PROPERTY_USAGE_RESTART_IF_CHANGED)); | |
if (theme_path!=String()) { | |
Ref<Theme> theme = ResourceLoader::load(theme_path); | |
if (theme.is_valid()) { | |
Theme::set_default(theme); | |
} | |
} else { | |
Ref<Font> font; | |
if (font_path!=String()) { | |
font=ResourceLoader::load(font_path); | |
} | |
make_default_theme(default_theme_hidpi,font); | |
} |
Basically the code that calls make_default_theme
loads a custom font if one is defined, but does not do the validity check, so it has to happen in make_default_theme
(and if no font is provided or if it's invalid, use the default fonts).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, ok, makes sense. I misunderstood the purpose of this code.
core/io/marshalls.cpp
Outdated
@@ -641,6 +641,7 @@ Error decode_variant(Variant& r_variant,const uint8_t *p_buffer, int p_len,int * | |||
|
|||
ERR_FAIL_COND_V(len<4,ERR_INVALID_DATA); | |||
uint32_t count = decode_uint32(buf); | |||
// count always > 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the ERR_FAIL_COND_V
test useful at all? count
is a uint32_t
, so it can't be < 0, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright, that's what your comment meant. Feel free to remove the checks then.
core/io/stream_peer.cpp
Outdated
@@ -492,6 +492,8 @@ Error StreamPeerBuffer::get_partial_data(uint8_t* p_buffer, int p_bytes,int &r_r | |||
|
|||
PoolVector<uint8_t>::Read r = data.read(); | |||
copymem(p_buffer,r.ptr(),r_received); | |||
|
|||
// return what? OK or ERR_* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Faless An idea maybe?
core/pool_allocator.cpp
Outdated
@@ -504,7 +504,7 @@ const void *PoolAllocator::get(ID p_mem) const { | |||
return NULL; | |||
} | |||
|
|||
if (e->pos<0 || (int)e->pos>=pool_size) { | |||
if (e->pos<0 || (int)e->pos>=pool_size) { // e->pos < 0 is always false, since pos is unsigned |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then remove that test :)
core/variant_parser.cpp
Outdated
@@ -1414,7 +1414,7 @@ Error VariantParser::parse_value(Token& token,Variant &value,Stream *p_stream,in | |||
return OK; | |||
} else if (id=="img") { // compatibility with godot.cfg | |||
|
|||
Token token; | |||
Token token; // no need for this declaration? the first argument in line 509 is a Token& token. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess the idea is that it shadows the other token
without modifying its data (while if it modified the Token&
reference it would change its data). Whether that's necessary or not, I don't know :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
modules/regex/regex.cpp
Outdated
@@ -321,7 +321,7 @@ struct RegExNodeClass : public RegExNode { | |||
case Type_lower: | |||
return ('a' <= c && c <= 'z'); | |||
case Type_print: | |||
return (0x1F < c && c < 0x1F); | |||
return (0x1F < c && c < 0x1F); // huh ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc @leezh
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahhh, it's supposed to be 7F
. Also, referring to the POSIX standards again, space is excluded too so it should actually be 0x20 < c && c < 0x7F
. 😅
scene/2d/particles_2d.cpp
Outdated
@@ -235,7 +235,7 @@ _FORCE_INLINE_ static float _rand_from_seed(uint32_t *seed) { | |||
s = 0x12345987; | |||
k = s / 127773; | |||
s = 16807 * (s - k * 127773) - 2836 * k; | |||
if (s < 0) | |||
if (s < 0) // but "s" is unsigned ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, why do we have this class rolling its own version of rand_from_seed
instead of using the Math one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Math::rand_form_seed() uses a different algorithm. Is it possible that this one was implemented to make sure it looks the same when ran on multiple systems, say for networking? This is just a guess of course.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, sorry. Indeed, I didn't even guess there would be multiple PRNG implementations in the code-base. I'll submit a PR ASAP
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Submitted PR #7904 for this one
core/pool_allocator.cpp
Outdated
@@ -546,7 +546,7 @@ void *PoolAllocator::get(ID p_mem) { | |||
return NULL; | |||
} | |||
|
|||
if (e->pos<0 || (int)e->pos>=pool_size) { | |||
if (e->pos<0 || (int)e->pos>=pool_size) { // e->pos < 0 is always false, since pos is unsigned |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh crap! I forgot to remove another one!
@@ -401,6 +401,7 @@ String ShaderCompilerGLES3::_dump_node_code(SL::Node *p_node, int p_level, Gener | |||
String scode = _dump_node_code(bnode->statements[i],p_level,r_gen_code,p_actions,p_default_actions); | |||
|
|||
if (bnode->statements[i]->type==SL::Node::TYPE_CONTROL_FLOW || bnode->statements[i]->type==SL::Node::TYPE_CONTROL_FLOW) { | |||
// if (A || A) ? I am hesitant to delete one of them, could be copy-paste error. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc @reduz.
scene/gui/rich_text_label.h
Outdated
@@ -173,7 +173,7 @@ class RichTextLabel : public Control { | |||
|
|||
struct ItemNewline : public Item { | |||
|
|||
int line; | |||
int line; // Overriding base's line ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds buggy indeed.
servers/visual/shader_language.cpp
Outdated
@@ -3241,7 +3241,7 @@ Error ShaderLanguage::_parse_shader(const Map< StringName, Map<StringName,DataTy | |||
_set_error("void datatype not allowed here"); | |||
return ERR_PARSE_ERROR; | |||
} | |||
if (!uniform && type<TYPE_FLOAT && type>TYPE_VEC4) { | |||
if (!uniform && type<TYPE_FLOAT && type>TYPE_VEC4) { // always false! should it be || instead? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc @reduz
@@ -1279,7 +1279,7 @@ Error ResourceImporterScene::import(const String& p_source_file, const String& p | |||
Ref<EditorScenePostImport> post_import_script; | |||
|
|||
if (post_import_script_path!="") { | |||
post_import_script_path = post_import_script_path; | |||
post_import_script_path = post_import_script_path; // is there a good reason for this? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc @reduz
core/variant.cpp
Outdated
@@ -2409,7 +2409,7 @@ Variant::Variant(const Object* p_object) { | |||
Variant::Variant(const Dictionary& p_dictionary) { | |||
|
|||
type=DICTIONARY; | |||
memnew_placement( _data._mem, (Dictionary)( p_dictionary) ); | |||
memnew_placement( _data._mem, (Dictionary)( p_dictionary) ); // shouldn't there be sizeof() for 2nd argument? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't need sizeof() the macro expands to :
_post_initialize(new(_data._mem,sizeof((Dictionary)( p_dictionary)),"") (Dictionary)( p_dictionary))
Nice work overall :) Could you squash the three commits together and edit the commit log to be explicit about the changes? Also it might be worth adding |
@akien-mga I hope I did this right :/ I did interactive rebase and squashed 4 commits.. Is it good? This is the first time doing this :) |
@RebelliousX What you want to do is this:
Once that is done when you do 'git log' all your old commits should be gone, instead having just the one commit with your new message. If that is what you see do git push -f <whatever your own fork's upstream is> If you're on IRC I can help you with this step by step if you'd like. |
6166127
to
2fa2b3b
Compare
@hpvb Thanks for the offer and the help. I am using Sourcetree on Windows, which is bogus unlike the Mac version. It kept insisting there was an error, apparently, the force push was disabled on the GUI, so I had to use the terminal in the end which was way easier. |
For anything git, the command line is always easier. Git is way too powerful and complex to be usable via a GUI past the basic "drag and drop-box" workflow that GitHub promotes :) |
scene/2d/particles_2d.cpp
Outdated
@@ -235,7 +235,7 @@ _FORCE_INLINE_ static float _rand_from_seed(uint32_t *seed) { | |||
s = 0x12345987; | |||
k = s / 127773; | |||
s = 16807 * (s - k * 127773) - 2836 * k; | |||
if (s < 0) | |||
if (s < 0) // FIXME: but "s" is unsigned ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is now fixed in master, so the addition of the comment should be rebased away as it conflicts.
@@ -353,6 +353,7 @@ void TextureRegionEditor::_region_input(const InputEvent& p_input) | |||
undo_redo->add_undo_method(atlas_tex.ptr(),"set_region",rect_prev); | |||
} | |||
else if(node_patch9){ | |||
// FIXME: Is this intentional? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can just remove that empty else if
so that the second one gets triggered.
@@ -3241,7 +3241,7 @@ Error ShaderLanguage::_parse_shader(const Map< StringName, Map<StringName,DataTy | |||
_set_error("void datatype not allowed here"); | |||
return ERR_PARSE_ERROR; | |||
} | |||
if (!uniform && type<TYPE_FLOAT && type>TYPE_VEC4) { | |||
if (!uniform && type<TYPE_FLOAT && type>TYPE_VEC4) { // FIXME: always false! should it be || instead? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it should be ||
.
@@ -492,6 +492,8 @@ Error StreamPeerBuffer::get_partial_data(uint8_t* p_buffer, int p_bytes,int &r_r | |||
|
|||
PoolVector<uint8_t>::Read r = data.read(); | |||
copymem(p_buffer,r.ptr(),r_received); | |||
|
|||
// FIXME: return what? OK or ERR_* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like the error handling is actually done in get_data
, where it returns ERR_INVALID_PARAMETER
if p_bytes != r_received
. So maybe this method here should be changed to return void
, or the error handling should be added directly here and get_data
should just return get_partial_data(p_buffer,p_bytes,recv)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've never used the StreamPeerBuffer
class myself but judging from the commit log of cbbcf72 and it's GDScript signature it looks cool.
get_partial_data
is inherited from PacketPeer
and we cannot change it's type.
It also appears to be exposed to GDScript StreamPeerBuffer.get_partial_data(...)
via StreamPeer::_get_partial_data(...)
.
It think this should return a proper error when needed, so option 2, something like
diff --git a/core/io/stream_peer.cpp b/core/io/stream_peer.cpp
index a64ebf2..399fbf9 100644
--- a/core/io/stream_peer.cpp
+++ b/core/io/stream_peer.cpp
@@ -470,21 +470,20 @@ Error StreamPeerBuffer::put_partial_data(const uint8_t* p_data,int p_bytes, int
Error StreamPeerBuffer::get_data(uint8_t* p_buffer, int p_bytes){
int recv;
- get_partial_data(p_buffer,p_bytes,recv);
- if (recv!=p_bytes)
- return ERR_INVALID_PARAMETER;
-
- return OK;
+ return get_partial_data(p_buffer,p_bytes,recv);
}
Error StreamPeerBuffer::get_partial_data(uint8_t* p_buffer, int p_bytes,int &r_received){
+ Error err = OK;
if (pointer+p_bytes > data.size()) {
+ err = ERR_FILE_EOF;
+
r_received=data.size()-pointer;
if (r_received<=0) {
r_received=0;
- return OK; //you got 0
+ return err; //you got 0
}
} else {
r_received=p_bytes;
@@ -492,6 +491,7 @@ Error StreamPeerBuffer::get_partial_data(uint8_t* p_buffer, int p_bytes,int &r_r
PoolVector<uint8_t>::Read r = data.read();
copymem(p_buffer,r.ptr(),r_received);
+ return err;
}
int StreamPeerBuffer::get_available_bytes() const {
Looks like SourceTree played one of its magic tricks again, you now have three commits instead of one ;) |
@akien-mga Actually, I used github's resolve conflict feature. I didn't touch Sourcetree till now, but now, it even refuses to do rebase because github merged branches I think :/ |
- Add FIXME tags comments to some unfixed potential bugs - Remove some checks (always false: unsigned never < 0) - Fix some if statements based on reviews. - Bunch of missing `else` statements
Let's merge the current state already as it's pretty good. I'll make sure the remaining FIXMEs get fixed soon too. |
@akien-mga @RebelliousX There are two bugs left unmarked (meaning no recognizable labels such as "FIXME"):
in
in
|
Added missing FIXMEs in PR #7878 [ci skip]
Some
else
statements are missing. Also, some of compound statements of the if-else are equal! I don't know if they are intentional.