Skip to content

Static analyzer-found cleanup opportunities#155

Open
ryandrake08 wants to merge 4 commits intorougier:masterfrom
ryandrake08:master
Open

Static analyzer-found cleanup opportunities#155
ryandrake08 wants to merge 4 commits intorougier:masterfrom
ryandrake08:master

Conversation

@ryandrake08
Copy link
Copy Markdown

A couple of issues found using clang's static analyzer. Most are pretty trivial (removal of unnecessary / unused code). Two moderately concerning ones:

  • The buffer shader_read() allocates is too large (sizeof char* vs sizeof char)
  • Potential memory leak in texture_font_load_glyph

Feel free to merge if you think it's helpful.

@rougier
Copy link
Copy Markdown
Owner

rougier commented Feb 11, 2017

Thanks! I've never used the clang static analyzer. I'll look into proposed modification and merge them.

else if( (set_fg == 0) && (code == 5) )
{
set_fg = 1;
code = 0;
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line prevents from ever entering the test just after. Do you know how the analyzer decides this can be safely removed ?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Observe line 177, code gets assigned 0 outside the if-else statement anyway, directly after line 128 is executed. So line 128 is redundant it seems.

float glyph_height = glyph->height * width/(float)glyph->width;
float glyph_width = glyph->width * height/(float)glyph->height;
int x = -glyph_width/2 + width/2.;
int y = -glyph_height/2 + height/2.;
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even if not used, this is relevant information. Maybe commenting those line would be better, no ?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I'll push a change with them added back, but commented out!

@ryandrake08
Copy link
Copy Markdown
Author

Thanks for the feedback. Adjustments made. This library is very useful by the way!

@rougier
Copy link
Copy Markdown
Owner

rougier commented Jun 9, 2017

@ryandrake08 Thanks for the fix. Just tell me you're ready for a merge.

@ryandrake08
Copy link
Copy Markdown
Author

Feel free to merge whenever. This PR is turning into a grab bag of warnings fixes and cleanups. The only change that may actually change the functionality of the library is 3df29ce. Please have a look at what this one is doing. You may prefer I leave this out. I found I needed it in my application to improve the look of my rendered text. Without this padding I was seeing undesired graphic artifacts around the edges of each glyph.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants