From d48d7b8819987430416c696f9286a601cdda2a3d Mon Sep 17 00:00:00 2001 From: Crayon2000 Date: Wed, 14 Jun 2017 00:02:41 -0400 Subject: [PATCH] Correct cppcheck warnings --- GRRLIB/GRRLIB/GRRLIB_bmf.c | 19 ++++++++++--------- GRRLIB/GRRLIB/GRRLIB_bmfx.c | 12 +++++------- GRRLIB/GRRLIB/GRRLIB_ttf.c | 3 ++- GRRLIB/GRRLIB/grrlib/GRRLIB_texSetup.h | 3 ++- 4 files changed, 19 insertions(+), 18 deletions(-) diff --git a/GRRLIB/GRRLIB/GRRLIB_bmf.c b/GRRLIB/GRRLIB/GRRLIB_bmf.c index 596289d..6a96a0e 100644 --- a/GRRLIB/GRRLIB/GRRLIB_bmf.c +++ b/GRRLIB/GRRLIB/GRRLIB_bmf.c @@ -80,20 +80,21 @@ GRRLIB_bytemapFont* GRRLIB_LoadBMF (const u8 my_bmf[] ) { /** * Free memory allocated by ByteMap fonts. + * If \a bmf is a null pointer, the function does nothing. + * @note This function does not change the value of \a bmf itself, hence it still points to the same (now invalid) location. * @param bmf A GRRLIB_bytemapFont structure. */ void GRRLIB_FreeBMF (GRRLIB_bytemapFont *bmf) { - u16 i; - - for (i=0; i<256; i++) { - if (bmf->charDef[i].data != NULL) { - free(bmf->charDef[i].data); + if (bmf != NULL) { + for (u16 i=0; i<256; i++) { + if (bmf->charDef[i].data != NULL) { + free(bmf->charDef[i].data); + } } + free(bmf->palette); + free(bmf->name); + free(bmf); } - free(bmf->palette); - free(bmf->name); - free(bmf); - bmf = NULL; } /** diff --git a/GRRLIB/GRRLIB/GRRLIB_bmfx.c b/GRRLIB/GRRLIB/GRRLIB_bmfx.c index 6dedec6..27068ed 100644 --- a/GRRLIB/GRRLIB/GRRLIB_bmfx.c +++ b/GRRLIB/GRRLIB/GRRLIB_bmfx.c @@ -67,19 +67,17 @@ void GRRLIB_BMFX_FlipV (const GRRLIB_texImg *texsrc, GRRLIB_texImg *texdest) { void GRRLIB_BMFX_Grayscale (const GRRLIB_texImg *texsrc, GRRLIB_texImg *texdest) { unsigned int x, y; - u8 gray; - u32 color; for (y = 0; y < texsrc->h; y++) { for (x = 0; x < texsrc->w; x++) { - color = GRRLIB_GetPixelFromtexImg(x, y, texsrc); + u32 color = GRRLIB_GetPixelFromtexImg(x, y, texsrc); - gray = ((R(color)* 77 + - G(color)*150 + - B(color)* 28 ) / 255); + u8 gray = ((R(color)* 77 + + G(color)*150 + + B(color)* 28 ) / 255); GRRLIB_SetPixelTotexImg(x, y, texdest, - ((gray << 24) | (gray << 16) | (gray << 8) | A(color))); + (gray << 24) | (gray << 16) | (gray << 8) | (A(color))); } } GRRLIB_SetHandle(texdest, 0, 0); diff --git a/GRRLIB/GRRLIB/GRRLIB_ttf.c b/GRRLIB/GRRLIB/GRRLIB_ttf.c index 63b12a9..cd15658 100644 --- a/GRRLIB/GRRLIB/GRRLIB_ttf.c +++ b/GRRLIB/GRRLIB/GRRLIB_ttf.c @@ -75,13 +75,14 @@ GRRLIB_ttfFont* GRRLIB_LoadTTF (const u8* file_base, s32 file_size) { /** * Free memory allocated by TTF fonts. + * If \a myFont is a null pointer, the function does nothing. + * @note This function does not change the value of \a myFont itself, hence it still points to the same (now invalid) location. * @param myFont A TTF. */ void GRRLIB_FreeTTF (GRRLIB_ttfFont *myFont) { if (myFont != NULL) { FT_Done_Face(myFont->face); free(myFont); - myFont = NULL; } } diff --git a/GRRLIB/GRRLIB/grrlib/GRRLIB_texSetup.h b/GRRLIB/GRRLIB/grrlib/GRRLIB_texSetup.h index 922a3b2..bc8b647 100644 --- a/GRRLIB/GRRLIB/grrlib/GRRLIB_texSetup.h +++ b/GRRLIB/GRRLIB/grrlib/GRRLIB_texSetup.h @@ -41,6 +41,8 @@ void GRRLIB_FlushTex (GRRLIB_texImg *tex) { /** * Free memory allocated for texture. + * If \a tex is a null pointer, the function does nothing. + * @note This function does not change the value of \a tex itself, hence it still points to the same (now invalid) location. * @param tex A GRRLIB_texImg structure. */ INLINE @@ -50,7 +52,6 @@ void GRRLIB_FreeTexture (GRRLIB_texImg *tex) { free(tex->data); } free(tex); - tex = NULL; } }