From: kosmirror <kos...@us...> - 2025-06-19 22:32:06
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "A pseudo Operating System for the Dreamcast.". The branch, master has been updated via 582833981e3c2de799094f2a0c3643104554361a (commit) from dd4514b72ac9e5a96660e5078c975c613d999300 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 582833981e3c2de799094f2a0c3643104554361a Author: QuzarDC <qu...@co...> Date: Sat May 31 02:33:49 2025 -0400 Fix various warnings in examples. Uninitialized variables, unused args, and signedness mismatches.nehe26 got a bit deeper of a cleanup in order to address unchecked allocations. ----------------------------------------------------------------------- Summary of changes: examples/dreamcast/2ndmix/2ndmix.c | 2 +- examples/dreamcast/basic/breaking/breaking.c | 2 +- examples/dreamcast/basic/mmu/nullptr/nullptr.c | 2 +- examples/dreamcast/cdrom/stream/cd-stream-test.c | 7 ++- examples/dreamcast/cpp/concurrency/concurrency.cpp | 2 +- examples/dreamcast/gldc/basic/vq/vq-example.c | 2 +- examples/dreamcast/gldc/nehe/nehe26/nehe26.c | 72 +++++++++++++--------- .../dreamcast/sound/ghettoplay-vorbis/songmenu.c | 2 + 8 files changed, 54 insertions(+), 37 deletions(-) diff --git a/examples/dreamcast/2ndmix/2ndmix.c b/examples/dreamcast/2ndmix/2ndmix.c index 25308251..90548f50 100644 --- a/examples/dreamcast/2ndmix/2ndmix.c +++ b/examples/dreamcast/2ndmix/2ndmix.c @@ -731,7 +731,7 @@ void font_one_frame(void) { } void font_init(void) { - int x, y, c; + size_t x, y, c; uint8 pcxpall[768]; volatile uint16 *vtex; uint16 val; diff --git a/examples/dreamcast/basic/breaking/breaking.c b/examples/dreamcast/basic/breaking/breaking.c index a7d673e4..e8108370 100644 --- a/examples/dreamcast/basic/breaking/breaking.c +++ b/examples/dreamcast/basic/breaking/breaking.c @@ -251,7 +251,7 @@ static bool break_on_sized_operand_region_access_value_range(void) { VERIFY(!handled); /* Read from the region-of-interest as the wrong data size. */ - volatile uint16_t tmp16; (void)tmp16; + volatile uint16_t tmp16 = 0; (void)tmp16; tmp16 = ((uint16_t *)vars)[1023 / sizeof(uint16_t)]; VERIFY(!handled); diff --git a/examples/dreamcast/basic/mmu/nullptr/nullptr.c b/examples/dreamcast/basic/mmu/nullptr/nullptr.c index 861570fd..7ae3a386 100644 --- a/examples/dreamcast/basic/mmu/nullptr/nullptr.c +++ b/examples/dreamcast/basic/mmu/nullptr/nullptr.c @@ -14,7 +14,7 @@ KOS_INIT_FLAGS(INIT_DEFAULT | INIT_MALLOCSTATS); -mmupage_t * catchnull(mmucontext_t * c, int vp) { +mmupage_t * catchnull(mmucontext_t *, int vp) { printf("Caught us trying to use a bad pointer!\n"); printf("The pointer page was %08x\n", vp << PAGESIZE_BITS); printf("The address of the attempt was %08lx\n", diff --git a/examples/dreamcast/cdrom/stream/cd-stream-test.c b/examples/dreamcast/cdrom/stream/cd-stream-test.c index b3a2044d..7a9e83bb 100644 --- a/examples/dreamcast/cdrom/stream/cd-stream-test.c +++ b/examples/dreamcast/cdrom/stream/cd-stream-test.c @@ -116,8 +116,8 @@ static int cd_stream_test(uint32_t lba, uint8_t *buffer, size_t size, int mode) return 0; } -int print_diff(uint8_t *pio_buf, uint8_t *dma_buf, size_t size) { - int i, j, rv = 0; +size_t print_diff(uint8_t *pio_buf, uint8_t *dma_buf, size_t size) { + size_t i, j, rv = 0; for(i = 0; i < size; ++i) { if (dma_buf[i] != pio_buf[i]) { @@ -143,7 +143,8 @@ int print_diff(uint8_t *pio_buf, uint8_t *dma_buf, size_t size) { } int main(int argc, char *argv[]) { - int rs, i; + int rs; + size_t i; uint32_t lba; CDROM_TOC toc; diff --git a/examples/dreamcast/cpp/concurrency/concurrency.cpp b/examples/dreamcast/cpp/concurrency/concurrency.cpp index b623f300..594663cf 100644 --- a/examples/dreamcast/cpp/concurrency/concurrency.cpp +++ b/examples/dreamcast/cpp/concurrency/concurrency.cpp @@ -147,7 +147,7 @@ static void test_semaphore() { struct LatchJob { const std::string name; std::string product{"not worked"}; - std::thread action; + std::thread action{std::thread()}; }; static void test_latch() { diff --git a/examples/dreamcast/gldc/basic/vq/vq-example.c b/examples/dreamcast/gldc/basic/vq/vq-example.c index 86b95ad1..acc79995 100644 --- a/examples/dreamcast/gldc/basic/vq/vq-example.c +++ b/examples/dreamcast/gldc/basic/vq/vq-example.c @@ -42,7 +42,7 @@ static int loadtxr(void) { 512, /* Texture Width */ 512, /* Texture Height */ 0, /* This bit must be set to 0 */ - fruit_end - fruit, /* Compressed Texture Size*/ + (uintptr_t)fruit_end - (uintptr_t)fruit, /* Compressed Texture Size*/ fruit); /* Address of texture data in RAM: OpenGL will load the texture into VRAM for you. Because of this, make sure to call glDeleteTextures() as needed, as that will free the VRAM allocated for the texture. */ diff --git a/examples/dreamcast/gldc/nehe/nehe26/nehe26.c b/examples/dreamcast/gldc/nehe/nehe26/nehe26.c index f5195162..fe1e563a 100644 --- a/examples/dreamcast/gldc/nehe/nehe26/nehe26.c +++ b/examples/dreamcast/gldc/nehe/nehe26/nehe26.c @@ -49,28 +49,32 @@ int key = 1; /* Make sure same morph key not pressed */ int step = 0, steps = 200; /* Step counter and maximum number of steps */ bool morph = false; /* Default morph to false (not morphing) */ -int maxver; /* Holds the max number of vertices */ +size_t maxver; /* Holds the max number of vertices */ object morph1, morph2, morph3, morph4, /* Our 4 morphable objects */ helper, *sour, *dest; /* Helper, source, destination object */ #define MORPHS 4 /* Function to allocate memory for an object */ -void objallocate(object *k, int n) { +bool objallocate(object *k, size_t n) { /* Sets points equal to vertex * number of vertices */ - k->points = (vertex *)malloc(sizeof(vertex) * n); + k->points = (vertex *)calloc(n, sizeof(vertex)); + + /* Check if we actually got memory back */ + if(k->points) + return true; + + return false; } /* Function deallocate memory for an object */ void objfree(object *k) { - free(k->points); } - /* Function to release/destroy our resources and restoring the old desktop */ -void Quit(int returnCode) { +void Quit(void) { /* Deallocate the objects' memory */ objfree(&morph1); @@ -81,42 +85,51 @@ void Quit(int returnCode) { } /* function Loads Object From File (name) */ -void objload(char *name, object *k) { +bool objload(char *name, object *k) { - int ver; /* Will hold vertex count */ + size_t ver; /* Will hold vertex count */ float rx, ry, rz; /* Hold vertex X, Y & Z position */ FILE *filein; /* Filename to open */ - int i; /* Simple loop variable */ + size_t i; /* Simple loop variable */ + bool rv = false; /* return value */ printf(" [objload] file: %s\n", name); /* Opens the file for reading */ filein = fopen(name, "r"); + + if(!filein) + return rv; + /* Reads the number of verts in the file */ fread(&ver, sizeof(int), 1, filein); /* Sets objects verts variable to equal the value of ver */ k->verts = ver; /* Jumps to code that allocates RAM to hold the object */ - objallocate(k, ver); - - /* Loops through the vertices */ - for(i = 0; i < ver; i++) { - /* Reads the next three verts */ - fread(&rx, sizeof(float), 1, filein); - fread(&ry, sizeof(float), 1, filein); - fread(&rz, sizeof(float), 1, filein); - /* Set our object's x, y, z points */ - k->points[i].x = rx; - k->points[i].y = ry; - k->points[i].z = rz; + if(objallocate(k, ver)) { + /* Loops through the vertices */ + for(i = 0; i < ver; i++) { + /* Reads the next three verts */ + fread(&rx, sizeof(float), 1, filein); + fread(&ry, sizeof(float), 1, filein); + fread(&rz, sizeof(float), 1, filein); + /* Set our object's x, y, z points */ + k->points[i].x = rx; + k->points[i].y = ry; + k->points[i].z = rz; + } + + /* If ver is greater than maxver set maxver equal to ver */ + if(ver > maxver) + maxver = ver; + + rv = true; } /* Close the file */ fclose(filein); - /* If ver is greater than maxver set maxver equal to ver */ - if(ver > maxver) - maxver = ver; + return rv; } /* Function to calculate movement of points during morphing */ @@ -133,7 +146,7 @@ vertex calculate(int i) { } /* General OpenGL initialization function */ -int initGL(GLvoid) { +bool initGL(GLvoid) { int i; /* Simple looping variable */ @@ -199,7 +212,7 @@ int initGL(GLvoid) { /* Source & destination are set to equal first object (morph1) */ sour = dest = &morph1; - return(true); + return true; } void draw_gl(void) { @@ -317,7 +330,8 @@ int main(int argc, char **argv) { /* Get basic stuff initialized */ glKosInit(); - initGL(); + if(!initGL()) + return EXIT_FAILURE; printf("Entering main loop\n"); @@ -383,7 +397,7 @@ int main(int argc, char **argv) { glKosSwapBuffers(); } - Quit(0); - return 0; + Quit(); + return EXIT_SUCCESS; } diff --git a/examples/dreamcast/sound/ghettoplay-vorbis/songmenu.c b/examples/dreamcast/sound/ghettoplay-vorbis/songmenu.c index 8c4d8f61..dccc685e 100644 --- a/examples/dreamcast/sound/ghettoplay-vorbis/songmenu.c +++ b/examples/dreamcast/sound/ghettoplay-vorbis/songmenu.c @@ -53,6 +53,7 @@ static int curpos = 0; static int filtinitted = 0; static void snd_hook(int strm, void * obj, int freq, int chn, void ** buf, int *req) { + (void)strm; (void)obj, (void)freq, (void)chn; int actual; uint64 t; @@ -115,6 +116,7 @@ static void draw_wave(void) { static void *load_song_list(void * p) { + (void)p; file_t d; d = fs_open(curdir, O_RDONLY | O_DIR); hooks/post-receive -- A pseudo Operating System for the Dreamcast. |