From 8d2935c32c5992f3b984ebabff195085c701ffdf Mon Sep 17 00:00:00 2001 From: "Azamat H. Hackimov" Date: Wed, 4 Sep 2024 14:26:33 +0300 Subject: [PATCH] Fix some warnings on uninitialized MVE variables --- libmve/mvelib.cpp | 25 ++++++++++++++++--------- libmve/mvelib.h | 4 ++-- libmve/mveplay.cpp | 2 +- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/libmve/mvelib.cpp b/libmve/mvelib.cpp index 0e538584..2cec7366 100644 --- a/libmve/mvelib.cpp +++ b/libmve/mvelib.cpp @@ -33,8 +33,8 @@ mve_cb_SetPalette mve_setpalette; /* * private utility functions */ -static short _mve_get_short(unsigned char *data); -static unsigned short _mve_get_ushort(unsigned char *data); +static short _mve_get_short(const unsigned char *data); +static unsigned short _mve_get_ushort(const unsigned char *data); /* * private functions for mvefile @@ -318,6 +318,8 @@ static void _mvefile_free(MVEFILE *movie) { * open the file stream in thie object */ static int _mvefile_open(MVEFILE *file, void *stream) { + if (!file) + return 0; file->stream = stream; if (!file->stream) return 0; @@ -343,7 +345,7 @@ static int _mvefile_read_header(MVEFILE *movie) { unsigned char buffer[26]; /* check the file is open */ - if (!movie->stream) + if (!movie || !movie->stream) return 0; /* check the file is long enough */ @@ -351,7 +353,7 @@ static int _mvefile_read_header(MVEFILE *movie) { return 0; /* check the signature */ - if (memcmp(buffer, MVE_HEADER, 20)) + if (memcmp(buffer, MVE_HEADER, 20) != 0) return 0; /* check the hard-coded constants */ @@ -366,6 +368,9 @@ static int _mvefile_read_header(MVEFILE *movie) { } static void _mvefile_set_buffer_size(MVEFILE *movie, int buf_size) { + if (!movie) + return; + unsigned char *new_buffer; int new_len; @@ -384,7 +389,7 @@ static void _mvefile_set_buffer_size(MVEFILE *movie, int buf_size) { /* free old buffer */ if (movie->cur_chunk) { mve_free(movie->cur_chunk); - movie->cur_chunk = 0; + movie->cur_chunk = nullptr; } /* install new buffer */ @@ -397,7 +402,7 @@ static int _mvefile_fetch_next_chunk(MVEFILE *movie) { unsigned short length; /* fail if not open */ - if (!movie->stream) + if (!movie || !movie->stream) return 0; /* fail if we can't read the next segment descriptor */ @@ -419,13 +424,13 @@ static int _mvefile_fetch_next_chunk(MVEFILE *movie) { return 1; } -static short _mve_get_short(unsigned char *data) { +static short _mve_get_short(const unsigned char *data) { short value; value = data[0] | (data[1] << 8); return value; } -static unsigned short _mve_get_ushort(unsigned char *data) { +static unsigned short _mve_get_ushort(const unsigned char *data) { unsigned short value; value = data[0] | (data[1] << 8); return value; @@ -440,7 +445,7 @@ static MVESTREAM *_mvestream_alloc() { /* allocate and zero-initialize everything */ movie = (MVESTREAM *)mve_alloc(sizeof(MVESTREAM)); movie->movie = nullptr; - movie->context = 0; + movie->context = nullptr; memset(movie->handlers, 0, sizeof(movie->handlers)); return movie; @@ -469,6 +474,8 @@ static void _mvestream_free(MVESTREAM *movie) { * open an MVESTREAM object */ static int _mvestream_open(MVESTREAM *movie, void *stream) { + if (!movie) + return 0; movie->movie = mvefile_open(stream); return (movie->movie == nullptr) ? 0 : 1; diff --git a/libmve/mvelib.h b/libmve/mvelib.h index abb1d34f..d67930de 100644 --- a/libmve/mvelib.h +++ b/libmve/mvelib.h @@ -23,7 +23,7 @@ /* callback for reading stream */ typedef unsigned int (*mve_cb_Read)(void *stream, void *buffer, unsigned int count); -/* callback for memore allocating */ +/* callback for memory allocating */ typedef void *(*mve_cb_Alloc)(unsigned int size); /* callback for memory freeing */ typedef void (*mve_cb_Free)(void *ptr); @@ -76,7 +76,7 @@ void MVE_rmEndMovie(MVESTREAM *mve); void MVE_getVideoSpec(MVE_videoSpec *vSpec); // Initialize MVE sound. Set `enable` to false if sound should not be enabled. -void MVE_sndInit(const bool enable); +void MVE_sndInit(bool enable); void MVE_ioCallbacks(mve_cb_Read io_read); void MVE_memCallbacks(mve_cb_Alloc mem_alloc, mve_cb_Free mem_free); diff --git a/libmve/mveplay.cpp b/libmve/mveplay.cpp index 9355d0d0..9df8560c 100644 --- a/libmve/mveplay.cpp +++ b/libmve/mveplay.cpp @@ -470,7 +470,7 @@ void MVE_rmEndMovie(MVESTREAM *mve) { void MVE_rmHoldMovie() { timer_started = 0; } -void MVE_sndInit(const bool enable) { +void MVE_sndInit(bool enable) { #ifdef AUDIO if (enable) { mve_audio_enabled = 1;