From 528209831fc8f188df895acae83174bb81996c96 Mon Sep 17 00:00:00 2001 From: dario-loi Date: Wed, 27 Nov 2024 14:26:58 +0100 Subject: Code quality and warning removal Solved all code quality issues, removed dead code. Correctly freed fps buffer in texture_show_fps.c Correctly checked for argc size before accessing argv (did not show up in warnings but it's still dangerous) Reordered some resource acquisition operations in examples in order to avoid framebuffer creation if wrong inputs are specified (we fail first). --- examples/texture_show_fps.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'examples/texture_show_fps.c') diff --git a/examples/texture_show_fps.c b/examples/texture_show_fps.c index 90ddc4f..df54115 100644 --- a/examples/texture_show_fps.c +++ b/examples/texture_show_fps.c @@ -20,6 +20,12 @@ char *float_to_string(float value) int main(int argc, char **argv) { + if (argc < 3) { + fprintf(stderr, "Usage: %s \n", + argv[0]); + return EXIT_FAILURE; + } + // Initialize framebuffer fbgl_t framebuffer; if (fbgl_init(NULL, &framebuffer) != 0) { @@ -78,7 +84,11 @@ int main(int argc, char **argv) fbgl_render_psf1_text(&framebuffer, font, fps, 100, 0, 0xFF0000); - usleep(50000); // Delay to make the marquee effect visible (adjust as needed) + free(fps); + + nanosleep( + (struct timespec[]){ { 0, (int)5e7 } }, + NULL); // Delay to make the marquee effect visible (adjust as needed) framesize--; } -- cgit v1.2.3