Skip to content
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

Static analyzer-found cleanup opportunities #155

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
3 changes: 0 additions & 3 deletions demos/ansi.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,10 @@ ansi_to_markup( char *sequence, size_t length, markup_t *markup )
else if( (set_fg == 0) && (code == 5) )
{
set_fg = 1;
code = 0;
}
Copy link
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
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.

else if( (set_bg == 0) && (code == 5) )
{
set_bg = 1;
code = 0;
}
/* Set fg color (30 + x, where x is the index of the color) */
else if( (code >= 30) && (code < 38 ) )
Expand Down Expand Up @@ -210,7 +208,6 @@ print( text_buffer_t * buffer, vec2 * pen,
{
char *seq_start = text, *seq_end = text;
char *p;
size_t i;
for( p=text; p<(text+strlen(text)); ++p )
{
char *start = strstr( p, "\033[" );
Expand Down
7 changes: 0 additions & 7 deletions demos/distance-field-3.c
Original file line number Diff line number Diff line change
Expand Up @@ -305,16 +305,9 @@ void display( GLFWwindow* window )
glEnable( GL_BLEND );
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );

texture_glyph_t * glyph = texture_font_get_glyph( font, "@");

int width, height;
glfwGetFramebufferSize( window, &width, &height );

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.;

float s = .025+.975*(1+cos(angle/100.0))/2.;

vec4 color = {{1.0, 1.0, 1.0, 1.0 }};
Expand Down
2 changes: 1 addition & 1 deletion demos/shader.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ shader_read( const char *filename )
fseek( file, 0, SEEK_END );
size = ftell( file );
fseek(file, 0, SEEK_SET );
buffer = (char *) malloc( (size+1) * sizeof( char *) );
buffer = (char *) malloc( (size+1) * sizeof( char ) );
fread( buffer, sizeof(char), size, file );
buffer[size] = 0;
fclose( file );
Expand Down
1 change: 0 additions & 1 deletion texture-atlas.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ texture_atlas_fit( texture_atlas_t * self,
{
return -1;
}
y = node->y;
while( width_left > 0 )
{
node = (ivec3 *) (vector_get( self->nodes, i ));
Expand Down
2 changes: 1 addition & 1 deletion texture-font.c
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,6 @@ texture_font_load_glyph( texture_font_t * self,
int ft_glyph_left = 0;

ivec4 region;
size_t missed = 0;


if (!texture_font_load_face(self, self->size, &library, &face))
Expand All @@ -418,6 +417,7 @@ texture_font_load_glyph( texture_font_t * self,
if ( region.x < 0 )
{
fprintf( stderr, "Texture atlas is full (line %d)\n", __LINE__ );
texture_glyph_delete( glyph );
FT_Done_Face( face );
FT_Done_FreeType( library );
return NULL;
Expand Down