Skip to content

Commit fd14dc0

Browse files
committed
chore: silence codeQL warning about stb_image.h and other
1 parent 9abef13 commit fd14dc0

File tree

4 files changed

+18
-16
lines changed

4 files changed

+18
-16
lines changed

.github/workflows/codeql.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ jobs:
9090
-D SDL_RPATH=OFF
9191
9292
- name: Build and Install SDL3
93-
run: cmake --build build && sudo cmake --install build
93+
run: cmake --build build && sudo cmake --install build && rm -rf SDL
9494

9595
# If the analyze step fails for one of the languages you are analyzing with
9696
# "We were unable to automatically build your code", modify the matrix above

include/stb/stb_image.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1817,7 +1817,7 @@ static stbi__uint16 *stbi__convert_format16(stbi__uint16 *data, int img_n, int r
18171817
if (req_comp == img_n) return data;
18181818
STBI_ASSERT(req_comp >= 1 && req_comp <= 4);
18191819

1820-
good = (stbi__uint16 *) stbi__malloc(req_comp * x * y * 2);
1820+
good = (stbi__uint16 *) stbi__malloc((size_t)req_comp * x * y * 2);
18211821
if (good == NULL) {
18221822
STBI_FREE(data);
18231823
return (stbi__uint16 *) stbi__errpuc("outofmem", "Out of memory");
@@ -4821,7 +4821,7 @@ static int stbi__create_png_image_raw(stbi__png *a, stbi_uc *raw, stbi__uint32 r
48214821
stbi__create_png_alpha_expand8(dest, dest, x, img_n);
48224822
} else if (depth == 8) {
48234823
if (img_n == out_n)
4824-
memcpy(dest, cur, x*img_n);
4824+
memcpy(dest, cur, (size_t)x*img_n);
48254825
else
48264826
stbi__create_png_alpha_expand8(dest, cur, x, img_n);
48274827
} else if (depth == 16) {
@@ -6201,7 +6201,7 @@ static void *stbi__psd_load(stbi__context *s, int *x, int *y, int *comp, int req
62016201
out = (stbi_uc *) stbi__malloc_mad3(8, w, h, 0);
62026202
ri->bits_per_channel = 16;
62036203
} else
6204-
out = (stbi_uc *) stbi__malloc(4 * w*h);
6204+
out = (stbi_uc *) stbi__malloc((size_t)4 * w*h);
62056205

62066206
if (!out) return stbi__errpuc("outofmem", "Out of memory");
62076207
pixelCount = w*h;
@@ -6524,7 +6524,7 @@ static void *stbi__pic_load(stbi__context *s,int *px,int *py,int *comp,int req_c
65246524
// intermediate buffer is RGBA
65256525
result = (stbi_uc *) stbi__malloc_mad3(x, y, 4, 0);
65266526
if (!result) return stbi__errpuc("outofmem", "Out of memory");
6527-
memset(result, 0xff, x*y*4);
6527+
memset(result, 0xff, (size_t)x*y*4);
65286528

65296529
if (!stbi__pic_load_core(s,x,y,comp, result)) {
65306530
STBI_FREE(result);
@@ -6833,11 +6833,11 @@ static stbi_uc *stbi__gif_load_next(stbi__context *s, stbi__gif *g, int *comp, i
68336833
}
68346834

68356835
// background is what out is after the undoing of the previou frame;
6836-
memcpy( g->background, g->out, 4 * g->w * g->h );
6836+
memcpy( g->background, g->out, (size_t) 4 * g->w * g->h );
68376837
}
68386838

68396839
// clear my history;
6840-
memset( g->history, 0x00, g->w * g->h ); // pixels that were affected previous frame
6840+
memset( g->history, 0x00, (size_t) g->w * g->h ); // pixels that were affected previous frame
68416841

68426842
for (;;) {
68436843
int tag = stbi__get8(s);
@@ -6963,12 +6963,12 @@ static void *stbi__load_gif_main_outofmem(stbi__gif *g, stbi_uc *out, int **dela
69636963
static void *stbi__load_gif_main(stbi__context *s, int **delays, int *x, int *y, int *z, int *comp, int req_comp)
69646964
{
69656965
if (stbi__gif_test(s)) {
6966-
int layers = 0;
6966+
size_t layers = 0;
69676967
stbi_uc *u = 0;
69686968
stbi_uc *out = 0;
69696969
stbi_uc *two_back = 0;
69706970
stbi__gif g;
6971-
int stride;
6971+
size_t stride = 0;
69726972
int out_size = 0;
69736973
int delays_size = 0;
69746974

src/engine.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ TextureBufferAndMemory Engine::LoadTextureFromFile(const std::string &name) {
335335

336336
fmt::println("Loading image {} ...", name);
337337
stbi_uc *imageData = stbi_load(name.data(), &texWidth, &texHeight, nullptr, STBI_rgb_alpha);
338-
VkDeviceSize imageSize = texWidth * texHeight * 4;
338+
VkDeviceSize imageSize = static_cast<VkDeviceSize>(texWidth * texHeight * 4);
339339

340340
if (!imageData)
341341
{
@@ -923,7 +923,7 @@ Glyph Engine::GenerateGlyph(EngineSharedContext &sharedContext, FT_Face ftFace,
923923
}
924924
}
925925

926-
VkDeviceSize glyphBufferSize = ftFace->glyph->bitmap.width * ftFace->glyph->bitmap.rows;
926+
VkDeviceSize glyphBufferSize = static_cast<VkDeviceSize>(ftFace->glyph->bitmap.width * ftFace->glyph->bitmap.rows);
927927

928928
TextureBufferAndMemory glyphBuffer{};
929929
AllocateBuffer(sharedContext, glyphBufferSize, VK_BUFFER_USAGE_TRANSFER_SRC_BIT, VK_MEMORY_PROPERTY_HOST_COHERENT_BIT | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, glyphBuffer.bufferAndMemory.buffer, glyphBuffer.bufferAndMemory.memory);

src/tinyfiledialogs.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,11 @@ misrepresented as being the original software.
9292
#else
9393
#include <limits.h>
9494
#include <unistd.h>
95+
#include <fcntl.h>
9596
#include <dirent.h> /* on old systems try <sys/dir.h> instead */
9697
#include <termios.h>
9798
#include <sys/utsname.h>
99+
#include <sys/stat.h>
98100
#include <signal.h> /* on old systems try <sys/signal.h> instead */
99101
#define TINYFD_SLASH "/"
100102
#endif /* _WIN32 */
@@ -393,19 +395,19 @@ static int fileExists( char const * aFilePathAndName )
393395

394396
static void wipefile(char const * aFilename)
395397
{
396-
int i;
398+
int i, fd;
397399
struct stat st;
398400
FILE * lIn;
399401

400-
if (stat(aFilename, &st) == 0)
402+
if ((fd = open(aFilename, O_WRONLY)) != -1)
401403
{
402-
if ((lIn = fopen(aFilename, "w")))
404+
if (fstat(fd, &st) == 0)
403405
{
404406
for (i = 0; i < st.st_size; i++)
405407
{
406-
fputc('A', lIn);
408+
write(fd, "A", 1);
407409
}
408-
fclose(lIn);
410+
close(fd);
409411
}
410412
}
411413
}

0 commit comments

Comments
 (0)