From 5fcb55591c310e144498cc28b1fabdee7c6e7dbd Mon Sep 17 00:00:00 2001 From: Sebastian Krzyszkowiak Date: Tue, 11 Dec 2018 00:26:51 +0100 Subject: [PATCH] fix cppcheck warnings --- src/libsuperderpy.c | 18 ++++++++++-------- src/shader.c | 2 +- src/utils.c | 1 - 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/libsuperderpy.c b/src/libsuperderpy.c index 1631846..1295a4b 100644 --- a/src/libsuperderpy.c +++ b/src/libsuperderpy.c @@ -187,13 +187,14 @@ SYMBOL_EXPORT struct Game* libsuperderpy_init(int argc, char** argv, const char* game->joystick = al_install_joystick(); } - int windowMode = ALLEGRO_FULLSCREEN_WINDOW; #ifdef ALLEGRO_ANDROID - windowMode |= ALLEGRO_FRAMELESS; -#endif -#ifdef __EMSCRIPTEN__ - windowMode = ALLEGRO_WINDOWED; + int windowMode = ALLEGRO_FULLSCREEN_WINDOW | ALLEGRO_FRAMELESS; +#elif defined(__EMSCRIPTEN__) + int windowMode = ALLEGRO_WINDOWED; +#else + int windowMode = ALLEGRO_FULLSCREEN_WINDOW; #endif + if (!game->config.fullscreen) { windowMode = ALLEGRO_WINDOWED; } @@ -282,9 +283,10 @@ SYMBOL_EXPORT struct Game* libsuperderpy_init(int argc, char** argv, const char* } int samplerate = strtol(GetConfigOptionDefault(game, "SuperDerpy", "samplerate", "44100"), NULL, 10); - ALLEGRO_AUDIO_DEPTH depth = ALLEGRO_AUDIO_DEPTH_FLOAT32; #ifdef ALLEGRO_ANDROID - depth = ALLEGRO_AUDIO_DEPTH_INT16; + ALLEGRO_AUDIO_DEPTH depth = ALLEGRO_AUDIO_DEPTH_INT16; +#else + ALLEGRO_AUDIO_DEPTH depth = ALLEGRO_AUDIO_DEPTH_FLOAT32; #endif game->audio.v = al_create_voice(samplerate, depth, ALLEGRO_CHANNEL_CONF_2); if (!game->audio.v) { @@ -510,7 +512,7 @@ SYMBOL_EXPORT void libsuperderpy_destroy(struct Game* game) { wchar_t* wargv[game->_priv.argc]; for (int i = 0; i < game->_priv.argc; i++) { size_t size = MultiByteToWideChar(CP_UTF8, 0, argv[i], -1, NULL, 0); - wargv[i] = alloca(sizeof(wchar_t) * size); + wargv[i] = malloc(sizeof(wchar_t) * size); MultiByteToWideChar(CP_UTF8, 0, argv[i], -1, wargv[i], size); } _wexecv(wargv[0], (const wchar_t* const*)wargv); diff --git a/src/shader.c b/src/shader.c index cf2b6cc..b64259c 100644 --- a/src/shader.c +++ b/src/shader.c @@ -40,7 +40,7 @@ static ALLEGRO_USTR* GetShaderSource(struct Game* game, const char* filename) { ALLEGRO_USTR_INFO info; n = al_fread(fp, buf, sizeof(buf)); - if (n <= 0) { + if (n == 0) { break; } al_ustr_append(str, al_ref_buffer(&info, buf, n)); diff --git a/src/utils.c b/src/utils.c index 317cf64..f519240 100644 --- a/src/utils.c +++ b/src/utils.c @@ -74,7 +74,6 @@ SYMBOL_EXPORT int DrawWrappedText(ALLEGRO_FONT* font, ALLEGRO_COLOR color, float pch = strtok_r(stext, " ", &context); // Get the first word. do { - strncpy(word, "", 255); // Truncate the string, to ensure there's no crazy stuff in there from memory. snprintf(word, 255, "%s ", pch); strncat(temp, word, 255); // Append the word to the end of TempLine // This code checks for the new line character.