Merge pull request #504 from Martinfx/master

Fix potential bugs from static analysis
This commit is contained in:
Ray 2018-04-02 18:10:38 +02:00 committed by GitHub
commit 3e0de31424
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 110 additions and 126 deletions

View file

@ -30,7 +30,7 @@ int main()
Vector3 cubePosition = { 0.0f, 1.0f, 0.0f }; Vector3 cubePosition = { 0.0f, 1.0f, 0.0f };
Vector3 cubeSize = { 2.0f, 2.0f, 2.0f }; Vector3 cubeSize = { 2.0f, 2.0f, 2.0f };
Ray ray; // Picking line ray Ray ray = {0.0f, 0.0f, 0.0f}; // Picking line ray
bool collision = false; bool collision = false;
@ -79,7 +79,6 @@ int main()
} }
DrawRay(ray, MAROON); DrawRay(ray, MAROON);
DrawGrid(10, 1.0f); DrawGrid(10, 1.0f);
End3dMode(); End3dMode();

View file

@ -193,6 +193,6 @@ void DrawAngleGauge(Texture2D angleGauge, int x, int y, float angle, char title[
DrawTexturePro(angleGauge, srcRec, dstRec, origin, angle, color); DrawTexturePro(angleGauge, srcRec, dstRec, origin, angle, color);
DrawText(FormatText("%5.1f°", angle), x - MeasureText(FormatText("%5.1f°", angle), textSize) / 2, y + 10, textSize, DARKGRAY); DrawText(FormatText("%5.1f", angle), x - MeasureText(FormatText("%5.1f", angle), textSize) / 2, y + 10, textSize, DARKGRAY);
DrawText(title, x - MeasureText(title, textSize) / 2, y + 60, textSize, DARKGRAY); DrawText(title, x - MeasureText(title, textSize) / 2, y + 60, textSize, DARKGRAY);
} }

View file

@ -76,7 +76,7 @@ int main()
{ {
// Initialization // Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
unsigned char key; static unsigned char key;
InitAudioDevice(); InitAudioDevice();

View file

@ -10,7 +10,6 @@
********************************************************************************************/ ********************************************************************************************/
#include "raylib.h" #include "raylib.h"
#include <stdlib.h> // Required for: malloc(), free() #include <stdlib.h> // Required for: malloc(), free()
#define MAX_BUNNIES 100000 // 100K bunnies #define MAX_BUNNIES 100000 // 100K bunnies
@ -33,6 +32,7 @@ int main()
Texture2D texBunny = LoadTexture("resources/wabbit_alpha.png"); Texture2D texBunny = LoadTexture("resources/wabbit_alpha.png");
Bunny *bunnies = (Bunny *)malloc(MAX_BUNNIES*sizeof(Bunny)); // Bunnies array Bunny *bunnies = (Bunny *)malloc(MAX_BUNNIES*sizeof(Bunny)); // Bunnies array
int bunniesCount = 0; // Bunnies counter int bunniesCount = 0; // Bunnies counter
SetTargetFPS(60); SetTargetFPS(60);
@ -72,7 +72,7 @@ int main()
ClearBackground(RAYWHITE); ClearBackground(RAYWHITE);
for (int i = 0; i <= bunniesCount; i++) for (int i = 0; i < bunniesCount; i++)
{ {
// NOTE: When internal QUADS batch limit is reached, a draw call is launched and // NOTE: When internal QUADS batch limit is reached, a draw call is launched and
// batching buffer starts being filled again; before launching the draw call, // batching buffer starts being filled again; before launching the draw call,
@ -84,7 +84,6 @@ int main()
DrawRectangle(0, 0, screenWidth, 40, LIGHTGRAY); DrawRectangle(0, 0, screenWidth, 40, LIGHTGRAY);
DrawText("raylib bunnymark", 10, 10, 20, DARKGRAY); DrawText("raylib bunnymark", 10, 10, 20, DARKGRAY);
DrawText(FormatText("bunnies: %i", bunniesCount), 400, 10, 20, RED); DrawText(FormatText("bunnies: %i", bunniesCount), 400, 10, 20, RED);
DrawFPS(260, 10); DrawFPS(260, 10);
EndDrawing(); EndDrawing();

View file

@ -39,7 +39,7 @@ int main()
SetPhysicsGravity(0, 0); SetPhysicsGravity(0, 0);
// Create random polygon physics body to shatter // Create random polygon physics body to shatter
PhysicsBody body = CreatePhysicsBodyPolygon((Vector2){ screenWidth/2, screenHeight/2 }, GetRandomValue(80, 200), GetRandomValue(3, 8), 10); CreatePhysicsBodyPolygon((Vector2){ screenWidth/2, screenHeight/2 }, GetRandomValue(80, 200), GetRandomValue(3, 8), 10);
SetTargetFPS(60); SetTargetFPS(60);
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
@ -53,7 +53,7 @@ int main()
if (needsReset) if (needsReset)
{ {
// Create random polygon physics body to shatter // Create random polygon physics body to shatter
body = CreatePhysicsBodyPolygon((Vector2){ screenWidth/2, screenHeight/2 }, GetRandomValue(80, 200), GetRandomValue(3, 8), 10); CreatePhysicsBodyPolygon((Vector2){ screenWidth/2, screenHeight/2 }, GetRandomValue(80, 200), GetRandomValue(3, 8), 10);
} }
if (IsKeyPressed('R')) // Reset physics input if (IsKeyPressed('R')) // Reset physics input

View file

@ -1553,7 +1553,7 @@ void UpdateMusicStream(Music music)
case MUSIC_AUDIO_OGG: case MUSIC_AUDIO_OGG:
{ {
// NOTE: Returns the number of samples to process (be careful! we ask for number of shorts!) // NOTE: Returns the number of samples to process (be careful! we ask for number of shorts!)
int numSamplesOgg = stb_vorbis_get_samples_short_interleaved(music->ctxOgg, music->stream.channels, (short *)pcm, samplesCount*music->stream.channels); stb_vorbis_get_samples_short_interleaved(music->ctxOgg, music->stream.channels, (short *)pcm, samplesCount*music->stream.channels);
} break; } break;
#if defined(SUPPORT_FILEFORMAT_FLAC) #if defined(SUPPORT_FILEFORMAT_FLAC)

14
src/external/jar_xm.h vendored
View file

@ -855,8 +855,6 @@ size_t jar_xm_get_memory_needed_for_context(const char* moddata, size_t moddata_
uint16_t num_instruments; uint16_t num_instruments;
/* Read the module header */ /* Read the module header */
num_channels = READ_U16(offset + 8);
num_channels = READ_U16(offset + 8); num_channels = READ_U16(offset + 8);
num_patterns = READ_U16(offset + 10); num_patterns = READ_U16(offset + 10);
@ -2573,16 +2571,10 @@ uint64_t jar_xm_get_remaining_samples(jar_xm_context_t* ctx)
return total; return total;
} }
//-------------------------------------------- //--------------------------------------------
//FILE LOADER - TODO - NEEDS TO BE CLEANED UP //FILE LOADER - TODO - NEEDS TO BE CLEANED UP
//-------------------------------------------- //--------------------------------------------
#undef DEBUG #undef DEBUG
#define DEBUG(...) do { \ #define DEBUG(...) do { \
fprintf(stderr, __VA_ARGS__); \ fprintf(stderr, __VA_ARGS__); \
@ -2668,13 +2660,7 @@ int jar_xm_create_context_from_file(jar_xm_context_t** ctx, uint32_t rate, const
return 0; return 0;
} }
#endif//end of JAR_XM_IMPLEMENTATION #endif//end of JAR_XM_IMPLEMENTATION
//------------------------------------------------------------------------------- //-------------------------------------------------------------------------------
#endif//end of INCLUDE_JAR_XM_H #endif//end of INCLUDE_JAR_XM_H

1
src/external/rgif.h vendored
View file

@ -911,7 +911,6 @@ static void GifWriteLzwImage(FILE *f, unsigned char *image, unsigned int left, u
GifWriteCode(f, &stat, clearCode, codeSize); // clear tree GifWriteCode(f, &stat, clearCode, codeSize); // clear tree
memset(codetree, 0, sizeof(GifLzwNode)*4096); memset(codetree, 0, sizeof(GifLzwNode)*4096);
curCode = -1;
codeSize = minCodeSize + 1; codeSize = minCodeSize + 1;
maxCode = clearCode + 1; maxCode = clearCode + 1;
} }

View file

@ -493,7 +493,7 @@ float GetGesturePinchAngle(void)
// Returns angle from two-points vector with X-axis // Returns angle from two-points vector with X-axis
static float Vector2Angle(Vector2 v1, Vector2 v2) static float Vector2Angle(Vector2 v1, Vector2 v2)
{ {
float angle = angle = atan2f(v2.y - v1.y, v2.x - v1.x)*(180.0f/PI); float angle = atan2f(v2.y - v1.y, v2.x - v1.x)*(180.0f/PI);
if (angle < 0) angle += 360.0f; if (angle < 0) angle += 360.0f;

View file

@ -2375,7 +2375,7 @@ static Material LoadMTL(const char *fileName)
case 'n': // newmtl string Material name. Begins a new material description. case 'n': // newmtl string Material name. Begins a new material description.
{ {
// TODO: Support multiple materials in a single .mtl // TODO: Support multiple materials in a single .mtl
sscanf(buffer, "newmtl %s", mapFileName); sscanf(buffer, "newmtl %127s", mapFileName);
TraceLog(LOG_INFO, "[%s] Loading material...", mapFileName); TraceLog(LOG_INFO, "[%s] Loading material...", mapFileName);
} }
@ -2440,12 +2440,12 @@ static Material LoadMTL(const char *fileName)
{ {
if (buffer[5] == 'd') // map_Kd string Diffuse color texture map. if (buffer[5] == 'd') // map_Kd string Diffuse color texture map.
{ {
result = sscanf(buffer, "map_Kd %s", mapFileName); result = sscanf(buffer, "map_Kd %127s", mapFileName);
if (result != EOF) material.maps[MAP_DIFFUSE].texture = LoadTexture(mapFileName); if (result != EOF) material.maps[MAP_DIFFUSE].texture = LoadTexture(mapFileName);
} }
else if (buffer[5] == 's') // map_Ks string Specular color texture map. else if (buffer[5] == 's') // map_Ks string Specular color texture map.
{ {
result = sscanf(buffer, "map_Ks %s", mapFileName); result = sscanf(buffer, "map_Ks %127s", mapFileName);
if (result != EOF) material.maps[MAP_SPECULAR].texture = LoadTexture(mapFileName); if (result != EOF) material.maps[MAP_SPECULAR].texture = LoadTexture(mapFileName);
} }
else if (buffer[5] == 'a') // map_Ka string Ambient color texture map. else if (buffer[5] == 'a') // map_Ka string Ambient color texture map.
@ -2455,12 +2455,12 @@ static Material LoadMTL(const char *fileName)
} break; } break;
case 'B': // map_Bump string Bump texture map. case 'B': // map_Bump string Bump texture map.
{ {
result = sscanf(buffer, "map_Bump %s", mapFileName); result = sscanf(buffer, "map_Bump %127s", mapFileName);
if (result != EOF) material.maps[MAP_NORMAL].texture = LoadTexture(mapFileName); if (result != EOF) material.maps[MAP_NORMAL].texture = LoadTexture(mapFileName);
} break; } break;
case 'b': // map_bump string Bump texture map. case 'b': // map_bump string Bump texture map.
{ {
result = sscanf(buffer, "map_bump %s", mapFileName); result = sscanf(buffer, "map_bump %127s", mapFileName);
if (result != EOF) material.maps[MAP_NORMAL].texture = LoadTexture(mapFileName); if (result != EOF) material.maps[MAP_NORMAL].texture = LoadTexture(mapFileName);
} break; } break;
case 'd': // map_d string Opacity texture map. case 'd': // map_d string Opacity texture map.
@ -2485,7 +2485,7 @@ static Material LoadMTL(const char *fileName)
} break; } break;
case 'b': // bump string Bump texture map case 'b': // bump string Bump texture map
{ {
result = sscanf(buffer, "bump %s", mapFileName); result = sscanf(buffer, "bump %127s", mapFileName);
if (result != EOF) material.maps[MAP_NORMAL].texture = LoadTexture(mapFileName); if (result != EOF) material.maps[MAP_NORMAL].texture = LoadTexture(mapFileName);
} break; } break;
case 'T': // Tr float Transparency Tr (alpha). Tr is inverse of d case 'T': // Tr float Transparency Tr (alpha). Tr is inverse of d

View file

@ -3373,9 +3373,9 @@ static void LoadBuffersDefault(void)
quads.texcoords = (float *)malloc(sizeof(float)*2*4*MAX_QUADS_BATCH); // 2 float by texcoord, 4 texcoord by quad quads.texcoords = (float *)malloc(sizeof(float)*2*4*MAX_QUADS_BATCH); // 2 float by texcoord, 4 texcoord by quad
quads.colors = (unsigned char *)malloc(sizeof(unsigned char)*4*4*MAX_QUADS_BATCH); // 4 float by color, 4 colors by quad quads.colors = (unsigned char *)malloc(sizeof(unsigned char)*4*4*MAX_QUADS_BATCH); // 4 float by color, 4 colors by quad
#if defined(GRAPHICS_API_OPENGL_33) #if defined(GRAPHICS_API_OPENGL_33)
quads.indices = (unsigned int *)malloc(sizeof(int)*6*MAX_QUADS_BATCH); // 6 int by quad (indices) quads.indices = (unsigned int *)malloc(sizeof(unsigned int)*6*MAX_QUADS_BATCH); // 6 int by quad (indices)
#elif defined(GRAPHICS_API_OPENGL_ES2) #elif defined(GRAPHICS_API_OPENGL_ES2)
quads.indices = (unsigned short *)malloc(sizeof(short)*6*MAX_QUADS_BATCH); // 6 int by quad (indices) quads.indices = (unsigned short *)malloc(sizeof(unsigned short)*6*MAX_QUADS_BATCH); // 6 int by quad (indices)
#endif #endif
for (int i = 0; i < (3*4*MAX_QUADS_BATCH); i++) quads.vertices[i] = 0.0f; for (int i = 0; i < (3*4*MAX_QUADS_BATCH); i++) quads.vertices[i] = 0.0f;

View file

@ -677,7 +677,7 @@ void ImageFormat(Image *image, int newFormat)
Color *pixels = GetImageData(*image); Color *pixels = GetImageData(*image);
free(image->data); // WARNING! We loose mipmaps data --> Regenerated at the end... free(image->data); // WARNING! We loose mipmaps data --> Regenerated at the end...
image->data = NULL;
image->format = newFormat; image->format = newFormat;
int k = 0; int k = 0;
@ -824,12 +824,13 @@ void ImageFormat(Image *image, int newFormat)
} }
free(pixels); free(pixels);
pixels = NULL;
// In case original image had mipmaps, generate mipmaps for formated image // In case original image had mipmaps, generate mipmaps for formated image
// NOTE: Original mipmaps are replaced by new ones, if custom mipmaps were used, they are lost // NOTE: Original mipmaps are replaced by new ones, if custom mipmaps were used, they are lost
if (image->mipmaps > 1) if (image->mipmaps > 1)
{ {
image->mipmaps = 1; image->mipmaps = 1;
assert(image->data != NULL);
ImageMipmaps(image); ImageMipmaps(image);
} }
} }