summaryrefslogtreecommitdiffhomepage
path: root/examples
diff options
context:
space:
mode:
authorRay <[email protected]>2023-11-01 15:28:18 +0100
committerRay <[email protected]>2023-11-01 15:28:18 +0100
commit64d64cc18114c02ecb068b20b6c4820df6182415 (patch)
treee95a1f4d95d5b3a09492ec54c2566047a588c275 /examples
parentba21b8d2744b39dadc6b17b9091a30cc5e00f0b8 (diff)
downloadraylib-64d64cc18114c02ecb068b20b6c4820df6182415.tar.gz
raylib-64d64cc18114c02ecb068b20b6c4820df6182415.zip
REVIEWED: Potential code issues reported by CodeQL #3476
Diffstat (limited to 'examples')
-rw-r--r--examples/core/core_automation_events.c6
-rw-r--r--examples/core/core_loading_thread.c2
-rw-r--r--examples/core/core_random_values.c2
-rw-r--r--examples/models/models_skybox.c13
-rw-r--r--examples/others/raymath_vector_angle.c2
-rw-r--r--examples/shaders/shaders_raymarching.c3
-rw-r--r--examples/text/text_unicode.c18
7 files changed, 24 insertions, 22 deletions
diff --git a/examples/core/core_automation_events.c b/examples/core/core_automation_events.c
index 27711b39..0739a6e7 100644
--- a/examples/core/core_automation_events.c
+++ b/examples/core/core_automation_events.c
@@ -75,9 +75,9 @@ int main(void)
bool eventRecording = false;
bool eventPlaying = false;
- int frameCounter = 0;
- int playFrameCounter = 0;
- int currentPlayFrame = 0;
+ unsigned int frameCounter = 0;
+ unsigned int playFrameCounter = 0;
+ unsigned int currentPlayFrame = 0;
SetTargetFPS(60);
//--------------------------------------------------------------------------------------
diff --git a/examples/core/core_loading_thread.c b/examples/core/core_loading_thread.c
index 0538dcee..8451ff03 100644
--- a/examples/core/core_loading_thread.c
+++ b/examples/core/core_loading_thread.c
@@ -41,7 +41,7 @@ int main(void)
InitWindow(screenWidth, screenHeight, "raylib [core] example - loading thread");
- pthread_t threadId; // Loading data thread id
+ pthread_t threadId = { 0 }; // Loading data thread id
enum { STATE_WAITING, STATE_LOADING, STATE_FINISHED } state = STATE_WAITING;
int framesCounter = 0;
diff --git a/examples/core/core_random_values.c b/examples/core/core_random_values.c
index c2225bca..bec1de27 100644
--- a/examples/core/core_random_values.c
+++ b/examples/core/core_random_values.c
@@ -29,7 +29,7 @@ int main(void)
int randValue = GetRandomValue(-8, 5); // Get a random integer number between -8 and 5 (both included)
- int framesCounter = 0; // Variable used to count frames
+ unsigned int framesCounter = 0; // Variable used to count frames
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------
diff --git a/examples/models/models_skybox.c b/examples/models/models_skybox.c
index 7a500e04..c583128b 100644
--- a/examples/models/models_skybox.c
+++ b/examples/models/models_skybox.c
@@ -68,14 +68,12 @@ int main(void)
char skyboxFileName[256] = { 0 };
- Texture2D panorama;
-
if (useHDR)
{
TextCopy(skyboxFileName, "resources/dresden_square_2k.hdr");
// Load HDR panorama (sphere) texture
- panorama = LoadTexture(skyboxFileName);
+ Texture2D panorama = LoadTexture(skyboxFileName);
// Generate cubemap (texture with 6 quads-cube-mapping) from panorama HDR texture
// NOTE 1: New texture is generated rendering to texture, shader calculates the sphere->cube coordinates mapping
@@ -83,7 +81,7 @@ int main(void)
// despite texture can be successfully created.. so using PIXELFORMAT_UNCOMPRESSED_R8G8B8A8 instead of PIXELFORMAT_UNCOMPRESSED_R32G32B32A32
skybox.materials[0].maps[MATERIAL_MAP_CUBEMAP].texture = GenTextureCubemap(shdrCubemap, panorama, 1024, PIXELFORMAT_UNCOMPRESSED_R8G8B8A8);
- //UnloadTexture(panorama); // Texture not required anymore, cubemap already generated
+ UnloadTexture(panorama); // Texture not required anymore, cubemap already generated
}
else
{
@@ -113,15 +111,18 @@ int main(void)
{
if (IsFileExtension(droppedFiles.paths[0], ".png;.jpg;.hdr;.bmp;.tga"))
{
- // Unload current cubemap texture and load new one
+ // Unload current cubemap texture to load new one
UnloadTexture(skybox.materials[0].maps[MATERIAL_MAP_CUBEMAP].texture);
+
if (useHDR)
{
+ // Load HDR panorama (sphere) texture
Texture2D panorama = LoadTexture(droppedFiles.paths[0]);
// Generate cubemap from panorama texture
skybox.materials[0].maps[MATERIAL_MAP_CUBEMAP].texture = GenTextureCubemap(shdrCubemap, panorama, 1024, PIXELFORMAT_UNCOMPRESSED_R8G8B8A8);
- UnloadTexture(panorama);
+
+ UnloadTexture(panorama); // Texture not required anymore, cubemap already generated
}
else
{
diff --git a/examples/others/raymath_vector_angle.c b/examples/others/raymath_vector_angle.c
index ad573f54..d0f81548 100644
--- a/examples/others/raymath_vector_angle.c
+++ b/examples/others/raymath_vector_angle.c
@@ -42,7 +42,7 @@ int main(void)
{
// Update
//----------------------------------------------------------------------------------
- float startangle;
+ float startangle = 0.0f;
if (angleMode == 0) startangle = -Vector2LineAngle(v0, v1)*RAD2DEG;
if (angleMode == 1) startangle = 0.0f;
diff --git a/examples/shaders/shaders_raymarching.c b/examples/shaders/shaders_raymarching.c
index e9b7755a..ff403e61 100644
--- a/examples/shaders/shaders_raymarching.c
+++ b/examples/shaders/shaders_raymarching.c
@@ -82,7 +82,8 @@ int main(void)
// Check if screen is resized
if (IsWindowResized())
{
- float resolution[2] = { (float)GetScreenWidth(), (float)GetScreenHeight() };
+ resolution[0] = (float)GetScreenWidth();
+ resolution[1] = (float)GetScreenHeight();
SetShaderValue(shader, resolutionLoc, resolution, SHADER_UNIFORM_VEC2);
}
//----------------------------------------------------------------------------------
diff --git a/examples/text/text_unicode.c b/examples/text/text_unicode.c
index b25e3273..42227f89 100644
--- a/examples/text/text_unicode.c
+++ b/examples/text/text_unicode.c
@@ -195,7 +195,7 @@ int main(void)
}
Vector2 mouse = GetMousePosition();
- Vector2 pos = { 28.8f, 10.0f };
+ Vector2 position = { 28.8f, 10.0f };
hovered = -1;
//----------------------------------------------------------------------------------
@@ -210,21 +210,21 @@ int main(void)
for (int i = 0; i < SIZEOF(emoji); ++i)
{
const char *txt = &emojiCodepoints[emoji[i].index];
- Rectangle emojiRect = { pos.x, pos.y, (float)fontEmoji.baseSize, (float)fontEmoji.baseSize };
+ Rectangle emojiRect = { position.x, position.y, (float)fontEmoji.baseSize, (float)fontEmoji.baseSize };
if (!CheckCollisionPointRec(mouse, emojiRect))
{
- DrawTextEx(fontEmoji, txt, pos, (float)fontEmoji.baseSize, 1.0f, selected == i ? emoji[i].color : Fade(LIGHTGRAY, 0.4f));
+ DrawTextEx(fontEmoji, txt, position, (float)fontEmoji.baseSize, 1.0f, selected == i ? emoji[i].color : Fade(LIGHTGRAY, 0.4f));
}
else
{
- DrawTextEx(fontEmoji, txt, pos, (float)fontEmoji.baseSize, 1.0f, emoji[i].color );
+ DrawTextEx(fontEmoji, txt, position, (float)fontEmoji.baseSize, 1.0f, emoji[i].color );
hovered = i;
- hoveredPos = pos;
+ hoveredPos = position;
}
- if ((i != 0) && (i%EMOJI_PER_WIDTH == 0)) { pos.y += fontEmoji.baseSize + 24.25f; pos.x = 28.8f; }
- else pos.x += fontEmoji.baseSize + 28.8f;
+ if ((i != 0) && (i%EMOJI_PER_WIDTH == 0)) { position.y += fontEmoji.baseSize + 24.25f; position.x = 28.8f; }
+ else position.x += fontEmoji.baseSize + 28.8f;
}
//------------------------------------------------------------------------------
@@ -282,8 +282,8 @@ int main(void)
int length = GetCodepointCount(messages[message].text);
const char *info = TextFormat("%s %u characters %i bytes", messages[message].language, length, size);
sz = MeasureTextEx(GetFontDefault(), info, 10, 1.0f);
- Vector2 pos = { textRect.x + textRect.width - sz.x, msgRect.y + msgRect.height - sz.y - 2 };
- DrawText(info, (int)pos.x, (int)pos.y, 10, RAYWHITE);
+
+ DrawText(info, (int)(textRect.x + textRect.width - sz.x), (int)(msgRect.y + msgRect.height - sz.y - 2), 10, RAYWHITE);
}
//------------------------------------------------------------------------------