aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoão Coelho <jotac0@users.noreply.github.com>2019-10-29 14:57:19 +0000
committerRay <raysan5@gmail.com>2019-10-29 15:57:19 +0100
commit75b0264f35d8895c1e64c7c7bc85d1572d167cf2 (patch)
treed02dd8ce1f168e60c5f7e9551b9dca1101fdf51b
parent64c588e9d8e9cb34da4fe592ae091d62f59d6853 (diff)
downloadraylib-75b0264f35d8895c1e64c7c7bc85d1572d167cf2.tar.gz
raylib-75b0264f35d8895c1e64c7c7bc85d1572d167cf2.zip
fix various problems, thanks CppCheck :) (#1005)
* explained a bit more the core_window_letterbox example * fixed a few 'ups' moments that could lead to mild head pain and time loss
-rw-r--r--src/models.c4
-rw-r--r--src/physac.h27
-rw-r--r--src/raudio.c3
-rw-r--r--src/rlgl.h7
-rw-r--r--src/shapes.c2
-rw-r--r--src/text.c2
-rw-r--r--src/textures.c2
7 files changed, 37 insertions, 10 deletions
diff --git a/src/models.c b/src/models.c
index 501f1e70..f70dd409 100644
--- a/src/models.c
+++ b/src/models.c
@@ -929,12 +929,16 @@ ModelAnimation *LoadModelAnimations(const char *filename, int *animCount)
{
TraceLog(LOG_ERROR, "Magic Number \"%s\"does not match.", iqm.magic);
fclose(iqmFile);
+
+ return NULL;
}
if (iqm.version != IQM_VERSION)
{
TraceLog(LOG_ERROR, "IQM version %i is incorrect.", iqm.version);
fclose(iqmFile);
+
+ return NULL;
}
// Get bones data
diff --git a/src/physac.h b/src/physac.h
index 4119feae..b23fb1af 100644
--- a/src/physac.h
+++ b/src/physac.h
@@ -842,9 +842,17 @@ PHYSACDEF void DestroyPhysicsBody(PhysicsBody body)
}
}
- #if defined(PHYSAC_DEBUG)
- if (index == -1) printf("[PHYSAC] cannot find body id %i in pointers array\n", id);
- #endif
+
+ if (index == -1){
+
+ #if defined(PHYSAC_DEBUG)
+ printf("[PHYSAC] cannot find body id %i in pointers array\n", id);
+ #endif
+
+ // prevent access to index -1
+ return;
+ }
+
// Free body allocated memory
PHYSAC_FREE(body);
@@ -1249,9 +1257,16 @@ static void DestroyPhysicsManifold(PhysicsManifold manifold)
}
}
- #if defined(PHYSAC_DEBUG)
- if (index == -1) printf("[PHYSAC] cannot find manifold id %i in pointers array\n", id);
- #endif
+
+ if (index == -1) {
+ #if defined(PHYSAC_DEBUG)
+ printf("[PHYSAC] cannot find manifold id %i in pointers array\n", id);
+ #endif
+
+ //prevent access to index -1
+ return;
+ }
+
// Free manifold allocated memory
PHYSAC_FREE(manifold);
diff --git a/src/raudio.c b/src/raudio.c
index 188c0532..f6a1e5f6 100644
--- a/src/raudio.c
+++ b/src/raudio.c
@@ -592,13 +592,14 @@ void SetMasterVolume(float volume)
AudioBuffer *InitAudioBuffer(ma_format format, ma_uint32 channels, ma_uint32 sampleRate, ma_uint32 bufferSizeInFrames, int usage)
{
AudioBuffer *audioBuffer = (AudioBuffer *)RL_CALLOC(1, sizeof(AudioBuffer));
- audioBuffer->buffer = RL_CALLOC(bufferSizeInFrames*channels*ma_get_bytes_per_sample(format), 1);
if (audioBuffer == NULL)
{
TraceLog(LOG_ERROR, "InitAudioBuffer() : Failed to allocate memory for audio buffer");
return NULL;
}
+
+ audioBuffer->buffer = RL_CALLOC(bufferSizeInFrames*channels*ma_get_bytes_per_sample(format), 1);
// Audio data runs through a format converter
ma_pcm_converter_config dspConfig;
diff --git a/src/rlgl.h b/src/rlgl.h
index b83da6e8..6eb215c0 100644
--- a/src/rlgl.h
+++ b/src/rlgl.h
@@ -1887,6 +1887,13 @@ unsigned int rlLoadTexture(void *data, int width, int height, int format, int mi
#endif
#endif // GRAPHICS_API_OPENGL_11
+ if( data == NULL ){
+ //ups!
+ TraceLog(LOG_WARNING, "Got asked to load texture from a NULL pointer!");
+
+ return id;
+ }
+
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glGenTextures(1, &id); // Generate texture id
diff --git a/src/shapes.c b/src/shapes.c
index 4fd4eff5..fc0fb00c 100644
--- a/src/shapes.c
+++ b/src/shapes.c
@@ -1524,7 +1524,7 @@ static float EaseCubicInOut(float t, float b, float c, float d)
// Get texture to draw shapes (RAII)
static Texture2D GetShapesTexture(void)
{
- if (texShapes.id <= 0)
+ if (texShapes.id == 0) //this variable is an unsigned int, will never be negative
{
#if defined(SUPPORT_FONT_TEXTURE)
texShapes = GetFontDefault().texture; // Use font texture white character
diff --git a/src/text.c b/src/text.c
index 6d55fa8d..3f8e22b1 100644
--- a/src/text.c
+++ b/src/text.c
@@ -1394,7 +1394,7 @@ char *TextToUtf8(int *codepoints, int length)
}
// Resize memory to text length + string NULL terminator
- realloc(text, size + 1);
+ text = realloc(text, size + 1);
return text;
}
diff --git a/src/textures.c b/src/textures.c
index ec08e3ac..967b6108 100644
--- a/src/textures.c
+++ b/src/textures.c
@@ -662,7 +662,7 @@ Vector4 *GetImageDataNormalized(Image image)
pixels[i].w = 1.0f;
k += 3;
- }
+ } break;
case UNCOMPRESSED_R32G32B32A32:
{
pixels[i].x = ((float *)image.data)[k];