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
12 changed files with 110 additions and 126 deletions

View File

@@ -1553,7 +1553,7 @@ void UpdateMusicStream(Music music)
case MUSIC_AUDIO_OGG:
{
// 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;
#if defined(SUPPORT_FILEFORMAT_FLAC)

18
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;
/* Read the module header */
num_channels = READ_U16(offset + 8);
num_channels = READ_U16(offset + 8);
num_patterns = READ_U16(offset + 10);
@@ -2561,28 +2559,22 @@ uint64_t jar_xm_get_remaining_samples(jar_xm_context_t* ctx)
uint64_t total = 0;
uint8_t currentLoopCount = jar_xm_get_loop_count(ctx);
jar_xm_set_max_loop_count(ctx, 0);
while(jar_xm_get_loop_count(ctx) == currentLoopCount)
{
total += ctx->remaining_samples_in_tick;
ctx->remaining_samples_in_tick = 0;
jar_xm_tick(ctx);
}
ctx->loop_count = currentLoopCount;
return total;
}
//--------------------------------------------
//FILE LOADER - TODO - NEEDS TO BE CLEANED UP
//--------------------------------------------
#undef DEBUG
#define DEBUG(...) do { \
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;
}
#endif//end of JAR_XM_IMPLEMENTATION
//-------------------------------------------------------------------------------
#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
memset(codetree, 0, sizeof(GifLzwNode)*4096);
curCode = -1;
codeSize = minCodeSize + 1;
maxCode = clearCode + 1;
}

View File

@@ -493,7 +493,7 @@ float GetGesturePinchAngle(void)
// Returns angle from two-points vector with X-axis
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;

View File

@@ -2347,7 +2347,7 @@ static Mesh LoadOBJ(const char *fileName)
// NOTE: Texture map parameters are not supported
static Material LoadMTL(const char *fileName)
{
#define MAX_BUFFER_SIZE 128
#define MAX_BUFFER_SIZE 128
Material material = { 0 };
@@ -2375,7 +2375,7 @@ static Material LoadMTL(const char *fileName)
case 'n': // newmtl string Material name. Begins a new material description.
{
// 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);
}
@@ -2440,12 +2440,12 @@ static Material LoadMTL(const char *fileName)
{
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);
}
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);
}
else if (buffer[5] == 'a') // map_Ka string Ambient color texture map.
@@ -2455,12 +2455,12 @@ static Material LoadMTL(const char *fileName)
} break;
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);
} break;
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);
} break;
case 'd': // map_d string Opacity texture map.
@@ -2485,7 +2485,7 @@ static Material LoadMTL(const char *fileName)
} break;
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);
} break;
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.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)
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)
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
for (int i = 0; i < (3*4*MAX_QUADS_BATCH); i++) quads.vertices[i] = 0.0f;

View File

@@ -16,7 +16,7 @@
* #define SUPPORT_FILEFORMAT_KTX
* #define SUPPORT_FILEFORMAT_PVR
* #define SUPPORT_FILEFORMAT_ASTC
* Selecte desired fileformats to be supported for image data loading. Some of those formats are
* Selecte desired fileformats to be supported for image data loading. Some of those formats are
* supported by default, to remove support, just comment unrequired #define in this module
*
* #define SUPPORT_IMAGE_MANIPULATION
@@ -112,7 +112,7 @@
#include "external/stb_image.h" // Required for: stbi_load_from_file()
// NOTE: Used to read image data (multiple formats support)
#endif
#if defined(SUPPORT_IMAGE_MANIPULATION)
#define STB_IMAGE_RESIZE_IMPLEMENTATION
#include "external/stb_image_resize.h" // Required for: stbir_resize_uint8()
@@ -188,14 +188,14 @@ Image LoadImage(const char *fileName)
int imgWidth = 0;
int imgHeight = 0;
int imgBpp = 0;
FILE *imFile = fopen(fileName, "rb");
if (imFile != NULL)
{
// NOTE: Using stb_image to load images (Supports: BMP, TGA, PNG, JPG, ...)
image.data = stbi_load_from_file(imFile, &imgWidth, &imgHeight, &imgBpp, 0);
fclose(imFile);
image.width = imgWidth;
@@ -212,24 +212,24 @@ Image LoadImage(const char *fileName)
else if (IsFileExtension(fileName, ".hdr"))
{
int imgBpp = 0;
FILE *imFile = fopen(fileName, "rb");
stbi_set_flip_vertically_on_load(true);
// Load 32 bit per channel floats data
// Load 32 bit per channel floats data
image.data = stbi_loadf_from_file(imFile, &image.width, &image.height, &imgBpp, 0);
stbi_set_flip_vertically_on_load(false);
fclose(imFile);
image.mipmaps = 1;
if (imgBpp == 1) image.format = UNCOMPRESSED_R32;
else if (imgBpp == 3) image.format = UNCOMPRESSED_R32G32B32;
else if (imgBpp == 4) image.format = UNCOMPRESSED_R32G32B32A32;
else
else
{
TraceLog(LOG_WARNING, "[%s] Image fileformat not supported", fileName);
UnloadImage(image);
@@ -319,10 +319,10 @@ Image LoadImageRaw(const char *fileName, int width, int height, int format, int
if (headerSize > 0) fseek(rawFile, headerSize, SEEK_SET);
unsigned int size = GetPixelDataSize(width, height, format);
image.data = malloc(size); // Allocate required memory in bytes
// NOTE: fread() returns num read elements instead of bytes,
// NOTE: fread() returns num read elements instead of bytes,
// to get bytes we need to read (1 byte size, elements) instead of (x byte size, 1 element)
int bytes = fread(image.data, 1, size, rawFile);
@@ -430,7 +430,7 @@ Color *GetImageData(Image image)
pixels[i].g = ((unsigned char *)image.data)[i];
pixels[i].b = ((unsigned char *)image.data)[i];
pixels[i].a = 255;
} break;
case UNCOMPRESSED_GRAY_ALPHA:
{
@@ -469,7 +469,7 @@ Color *GetImageData(Image image)
pixels[i].g = (unsigned char)((float)((pixel & 0b0000111100000000) >> 8)*(255/15));
pixels[i].b = (unsigned char)((float)((pixel & 0b0000000011110000) >> 4)*(255/15));
pixels[i].a = (unsigned char)((float)(pixel & 0b0000000000001111)*(255/15));
} break;
case UNCOMPRESSED_R8G8B8A8:
{
@@ -516,7 +516,7 @@ int GetPixelDataSize(int width, int height, int format)
case UNCOMPRESSED_R32G32B32: bpp = 32*3; break;
case UNCOMPRESSED_R32G32B32A32: bpp = 32*4; break;
case COMPRESSED_DXT1_RGB:
case COMPRESSED_DXT1_RGBA:
case COMPRESSED_DXT1_RGBA:
case COMPRESSED_ETC1_RGB:
case COMPRESSED_ETC2_RGB:
case COMPRESSED_PVRT_RGB:
@@ -530,7 +530,7 @@ int GetPixelDataSize(int width, int height, int format)
}
dataSize = width*height*bpp/8; // Total data size in bytes
return dataSize;
}
@@ -539,7 +539,7 @@ int GetPixelDataSize(int width, int height, int format)
Image GetTextureData(Texture2D texture)
{
Image image = { 0 };
if (texture.format < 8)
{
image.data = rlReadTexturePixels(texture);
@@ -550,7 +550,7 @@ Image GetTextureData(Texture2D texture)
image.height = texture.height;
image.format = texture.format;
image.mipmaps = 1;
// NOTE: Data retrieved on OpenGL ES 2.0 should be RGBA
// coming from FBO color buffer, but it seems original
// texture format is retrieved on RPI... weird...
@@ -597,15 +597,15 @@ Image ImageCopy(Image image)
for (int i = 0; i < image.mipmaps; i++)
{
size += GetPixelDataSize(width, height, image.format);
width /= 2;
height /= 2;
// Security check for NPOT textures
if (width < 1) width = 1;
if (height < 1) height = 1;
}
newImage.data = malloc(size);
if (newImage.data != NULL)
@@ -677,7 +677,7 @@ void ImageFormat(Image *image, int newFormat)
Color *pixels = GetImageData(*image);
free(image->data); // WARNING! We loose mipmaps data --> Regenerated at the end...
image->data = NULL;
image->format = newFormat;
int k = 0;
@@ -771,7 +771,7 @@ void ImageFormat(Image *image, int newFormat)
g = (unsigned char)(round((float)pixels[i].g*15.0f/255));
b = (unsigned char)(round((float)pixels[i].b*15.0f/255));
a = (unsigned char)(round((float)pixels[i].a*15.0f/255));
((unsigned short *)image->data)[i] = (unsigned short)r << 12 | (unsigned short)g << 8 | (unsigned short)b << 4 | (unsigned short)a;
}
@@ -791,7 +791,7 @@ void ImageFormat(Image *image, int newFormat)
case UNCOMPRESSED_R32:
{
image->data = (float *)malloc(image->width*image->height*sizeof(float));
for (int i = 0; i < image->width*image->height; i++)
{
((float *)image->data)[i] = (float)((float)pixels[i].r*0.299f/255.0f + (float)pixels[i].g*0.587f/255.0f + (float)pixels[i].b*0.114f/255.0f);
@@ -824,12 +824,13 @@ void ImageFormat(Image *image, int newFormat)
}
free(pixels);
pixels = NULL;
// 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
if (image->mipmaps > 1)
if (image->mipmaps > 1)
{
image->mipmaps = 1;
assert(image->data != NULL);
ImageMipmaps(image);
}
}