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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ harfbuzz/libfreetype-gl-hb.a

CMakeFiles
CMakeCache.txt
CTestTestfile.cmake
cmake_install.cmake
Makefile
libfreetype-gl.a
Expand Down
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
4 changes: 3 additions & 1 deletion demos/distance-field-3.c
Original file line number Diff line number Diff line change
Expand Up @@ -305,15 +305,17 @@ 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, "@");
/* 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.;

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
2 changes: 2 additions & 0 deletions opengl.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#elif defined(_WIN32) || defined(_WIN64)
# include <GL/glew.h>
# include <GL/wglew.h>
#elif defined(FREETYPE_GL_ES2_HEADER_ONLY)
# include <GLES2/gl2.h>
#else
# include <GL/glew.h>
# include <GL/gl.h>
Expand Down
2 changes: 1 addition & 1 deletion text-buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ text_buffer_add_text( text_buffer_t * self,
}
}

for( i = 0; utf8_strlen( text + i ) && length; i += utf8_surrogate_len( text + i ) )
for( i = 0; length; i += utf8_surrogate_len( text + i ) )
{
text_buffer_add_char( self, pen, markup, text + i, prev_character );
prev_character = text + i;
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
8 changes: 4 additions & 4 deletions texture-font.c
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ texture_font_load_glyph( texture_font_t * self,
FT_Library library;
FT_Error error;
FT_Face face;
FT_Glyph ft_glyph;
FT_Glyph ft_glyph = NULL;
FT_GlyphSlot slot;
FT_Bitmap ft_bitmap;

Expand All @@ -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,9 +417,10 @@ 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;
return 0;
}
texture_atlas_set_region( self->atlas, region.x, region.y, 4, 4, data, 0 );
glyph->codepoint = -1;
Expand Down Expand Up @@ -564,7 +564,7 @@ texture_font_load_glyph( texture_font_t * self,
int top;
int right;
int bottom;
} padding = { 0, 0, 1, 1 };
} padding = { 1, 1, 1, 1 };

if( self->rendermode == RENDER_SIGNED_DISTANCE_FIELD )
{
Expand Down
2 changes: 1 addition & 1 deletion vertex-buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ vertex_buffer_print( vertex_buffer_t * self )

assert(self);

fprintf( stderr, "%ld vertices, %ld indices\n",
fprintf( stderr, "%zd vertices, %zd indices\n",
vector_size( self->vertices ), vector_size( self->indices ) );
while( self->attributes[i] )
{
Expand Down