Fix warnings reported by clang-tidy

This commit is contained in:
Sebastian Krzyszkowiak 2020-04-25 19:28:47 +02:00
parent 4336b707c5
commit 312ff915f6
No known key found for this signature in database
GPG key ID: E8F235CF3BDBC3FF
9 changed files with 34 additions and 38 deletions

View file

@ -1 +1 @@
Checks: '*,-hicpp-no-assembler,-google-readability-todo,-misc-unused-parameters,-hicpp-signed-bitwise,-hicpp-multiway-paths-covered,-cert-msc30-c,-cert-msc50-cpp,-cert-msc32-c,-cert-msc51-cpp,-cppcoreguidelines-avoid-magic-numbers,-readability-magic-numbers,-bugprone-narrowing-conversions,-cppcoreguidelines-narrowing-conversions,-readability-isolate-declaration'
Checks: '*,-hicpp-no-assembler,-google-readability-todo,-misc-unused-parameters,-hicpp-signed-bitwise,-hicpp-multiway-paths-covered,-cert-msc30-c,-cert-msc50-cpp,-cert-msc32-c,-cert-msc51-cpp,-cppcoreguidelines-avoid-magic-numbers,-readability-magic-numbers,-bugprone-narrowing-conversions,-cppcoreguidelines-narrowing-conversions,-readability-isolate-declaration,-readability-non-const-parameter'

View file

@ -359,7 +359,7 @@ SYMBOL_EXPORT void RegisterSpritesheet(struct Game* game, struct Character* char
s->frames[i].flipX = strtolnull(al_get_config_value(config, framename, "flipX"), 0);
s->frames[i].flipY = strtolnull(al_get_config_value(config, framename, "flipY"), 0);
double r, g, b, a;
double r = 0, g = 0, b = 0, a = 0;
r = strtodnull(al_get_config_value(config, framename, "r"), 1);
g = strtodnull(al_get_config_value(config, framename, "g"), 1);
b = strtodnull(al_get_config_value(config, framename, "b"), 1);
@ -753,9 +753,9 @@ SYMBOL_EXPORT ALLEGRO_TRANSFORM GetCharacterTransform(struct Game* game, struct
SYMBOL_EXPORT ALLEGRO_COLOR GetCharacterTint(struct Game* game, struct Character* character) {
ALLEGRO_COLOR color;
if (character->parent && character->parent_tint) {
float r, g, b, a;
float r = 0, g = 0, b = 0, a = 0;
al_unmap_rgba_f(character->tint, &r, &g, &b, &a);
float r2, g2, b2, a2;
float r2 = 0, g2 = 0, b2 = 0, a2 = 0;
al_unmap_rgba_f(GetCharacterTint(game, character->parent), &r2, &g2, &b2, &a2);
color = al_map_rgba_f(r * r2, g * g2, b * b2, a * a2);
@ -763,7 +763,7 @@ SYMBOL_EXPORT ALLEGRO_COLOR GetCharacterTint(struct Game* game, struct Character
color = character->tint;
}
float r, g, b, a, r2, g2, b2, a2;
float r = 0, g = 0, b = 0, a = 0, r2 = 0, g2 = 0, b2 = 0, a2 = 0;
al_unmap_rgba_f(color, &r, &g, &b, &a);
al_unmap_rgba_f(character->frame->tint, &r2, &g2, &b2, &a2);
return al_map_rgba_f(r * r2, g * g2, b * b2, a * a2);

View file

@ -87,9 +87,9 @@ SYMBOL_INTERNAL void ImGui_ImplAllegro5_RenderDrawData(ImDrawData* draw_data) {
// Backup Allegro state that will be modified
ALLEGRO_TRANSFORM last_transform = *al_get_current_transform();
ALLEGRO_TRANSFORM last_projection_transform = *al_get_current_projection_transform();
int last_clip_x, last_clip_y, last_clip_w, last_clip_h;
int last_clip_x = 0, last_clip_y = 0, last_clip_w = 0, last_clip_h = 0;
al_get_clipping_rectangle(&last_clip_x, &last_clip_y, &last_clip_w, &last_clip_h);
int last_blender_op, last_blender_src, last_blender_dst;
int last_blender_op = 0, last_blender_src = 0, last_blender_dst = 0;
al_get_blender(&last_blender_op, &last_blender_src, &last_blender_dst);
// Setup desired render state
@ -165,8 +165,8 @@ SYMBOL_INTERNAL void ImGui_ImplAllegro5_RenderDrawData(ImDrawData* draw_data) {
SYMBOL_INTERNAL bool ImGui_ImplAllegro5_CreateDeviceObjects() {
// Build texture atlas
ImGuiIO* io = igGetIO();
unsigned char* pixels;
int width, height;
unsigned char* pixels = NULL;
int width = 0, height = 0;
ImFontAtlas_GetTexDataAsRGBA32(io->Fonts, &pixels, &width, &height, NULL);
// Create texture
@ -390,7 +390,7 @@ SYMBOL_INTERNAL void ImGui_ImplAllegro5_NewFrame() {
ImGuiIO* io = igGetIO();
// Setup display size (every frame to accommodate for window resizing)
int w, h;
int w = 0, h = 0;
w = al_get_display_width(g_Display);
h = al_get_display_height(g_Display);
io->DisplaySize = (ImVec2){.x = w, .y = h};

View file

@ -489,7 +489,7 @@ SYMBOL_INTERNAL struct List* FindInList(struct List* list, void* data, bool (*id
}
SYMBOL_INTERNAL void* RemoveFromList(struct List** list, void* data, bool (*identity)(struct List* elem, void* data)) {
struct List *prev = NULL, *tmp = *list, *start;
struct List *prev = NULL, *tmp = *list, *start = NULL;
void* d = NULL;
if (!identity) {
identity = Identity;
@ -521,7 +521,7 @@ SYMBOL_INTERNAL void* AddGarbage(struct Game* game, void* data) {
}
SYMBOL_INTERNAL void ClearGarbage(struct Game* game) {
struct List* tmp;
struct List* tmp = NULL;
while (game->_priv.garbage) {
free(game->_priv.garbage->data);
tmp = game->_priv.garbage->next;
@ -683,7 +683,7 @@ SYMBOL_INTERNAL char* GetGameName(struct Game* game, const char* format) {
static int HashString(struct Game* game, const char* str) {
unsigned long hash = 5381;
int c;
char c = 0;
while ((c = *str++)) {
hash = ((hash << 5) + hash) + c; /* hash * 33 + c */
@ -701,7 +701,7 @@ static bool RefCountIdentity(struct List* elem, void* data) {
SYMBOL_INTERNAL ALLEGRO_BITMAP* AddBitmap(struct Game* game, char* filename) {
int bucket = HashString(game, filename);
struct List* item = FindInList(game->_priv.bitmaps[bucket], filename, RefCountIdentity);
struct RefCount* rc;
struct RefCount* rc = NULL;
if (item) {
rc = item->data;
rc->counter++;

View file

@ -142,7 +142,7 @@ SYMBOL_EXPORT struct Game* libsuperderpy_init(int argc, char** argv, const char*
};
optind = 1;
int opt;
int opt = 0;
while ((opt = getopt_long(argc, argv, "dfw", long_options, NULL)) != -1) {
switch (opt) {
case 'd':
@ -533,7 +533,7 @@ SYMBOL_EXPORT void libsuperderpy_destroy(struct Game* game) {
ClearGarbage(game);
struct Gamestate *tmp = game->_priv.gamestates, *pom;
struct Gamestate *tmp = game->_priv.gamestates, *pom = NULL;
while (tmp) {
if (tmp->started) {
PrintConsole(game, "Stopping gamestate \"%s\"...", tmp->name);

View file

@ -108,7 +108,7 @@ SYMBOL_EXPORT bool FaderParticle(struct Game* game, struct ParticleState* partic
data->time += delta;
float r, g, b, a;
float r = 0, g = 0, b = 0, a = 0;
al_unmap_rgba_f(particle->tint, &r, &g, &b, &a);
r /= 1.0 - data->fade;
g /= 1.0 - data->fade;

View file

@ -33,7 +33,7 @@ static ALLEGRO_USTR* GetShaderSource(struct Game* game, const char* filename) {
while (true) {
char buf[512];
size_t n;
size_t n = 0;
ALLEGRO_USTR_INFO info;
n = al_fread(fp, buf, sizeof(buf));
@ -47,7 +47,7 @@ static ALLEGRO_USTR* GetShaderSource(struct Game* game, const char* filename) {
}
static bool AttachToShader(struct Game* game, ALLEGRO_SHADER* shader, ALLEGRO_SHADER_TYPE type, const char* filename) {
bool ret;
bool ret = 0;
if (filename) {
ALLEGRO_USTR* src = GetShaderSource(game, filename);
if (!src) {
@ -59,8 +59,7 @@ static bool AttachToShader(struct Game* game, ALLEGRO_SHADER* shader, ALLEGRO_SH
ret = al_attach_shader_source(shader, type, al_get_default_shader_source(al_get_shader_platform(shader), type));
}
if (!ret) {
const char* log;
log = al_get_shader_log(shader);
const char* log = al_get_shader_log(shader);
if (log) {
FatalError(game, false, "%s", log);
}

View file

@ -18,7 +18,7 @@
#include "internal.h"
static void DestroyArgs(struct TM_Arguments* args) {
struct TM_Arguments* pom;
struct TM_Arguments* pom = NULL;
while (args) {
pom = args->next;
free(args);
@ -129,8 +129,7 @@ SYMBOL_EXPORT void TM_Process(struct Timeline* timeline, double delta) {
delta = origDelta;
/* process all elements from background queue */
struct TM_Action *tmp, *tmp2, *pom = timeline->background;
tmp = NULL;
struct TM_Action *tmp = NULL, *tmp2 = NULL, *pom = timeline->background;
while (pom != NULL) {
bool destroy = false;
pom->delta = delta;
@ -297,7 +296,7 @@ SYMBOL_EXPORT void TM_AddDelay(struct Timeline* timeline, double delay) {
SYMBOL_EXPORT void TM_CleanQueue(struct Timeline* timeline) {
PrintConsole(timeline->game, "Timeline Manager[%s]: cleaning queue", timeline->name);
struct TM_Action *tmp, *pom = timeline->queue;
struct TM_Action *tmp = NULL, *pom = timeline->queue;
while (pom != NULL) {
if (*pom->function) {
if (pom->active) {
@ -318,7 +317,7 @@ SYMBOL_EXPORT void TM_CleanQueue(struct Timeline* timeline) {
SYMBOL_EXPORT void TM_CleanBackgroundQueue(struct Timeline* timeline) {
PrintConsole(timeline->game, "Timeline Manager[%s]: cleaning background queue", timeline->name);
struct TM_Action *tmp, *pom = timeline->background;
struct TM_Action *tmp = NULL, *pom = timeline->background;
while (pom != NULL) {
if (*pom->function) {
if (pom->active) {
@ -361,10 +360,9 @@ SYMBOL_EXPORT void TM_Destroy(struct Timeline* timeline) {
SYMBOL_EXPORT struct TM_Arguments* TM_AddToArgs(struct TM_Arguments* args, int num, ...) {
va_list ap;
int i;
va_start(ap, num);
struct TM_Arguments* tmp = args;
for (i = 0; i < num; i++) {
for (int i = 0; i < num; i++) {
if (!tmp) {
tmp = malloc(sizeof(struct TM_Arguments));
tmp->value = va_arg(ap, void*);

View file

@ -53,7 +53,7 @@ SYMBOL_EXPORT int DrawWrappedText(ALLEGRO_FONT* font, ALLEGRO_COLOR color, float
// TODO: use al_do_multiline_text; and switch to al_draw_multiline_text once it returns number of lines
char stext[1024]; // Copy of the passed text.
char* pch; // A pointer to each word.
char* pch = NULL; // A pointer to each word.
char word[255]; // A string containing the word (for convienence)
char* breakchar = "\n";
char lines[40][1024]; // A lovely array of strings to hold all the lines (40 max atm)
@ -76,7 +76,7 @@ SYMBOL_EXPORT int DrawWrappedText(ALLEGRO_FONT* font, ALLEGRO_COLOR color, float
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.
if (strncmp(word, breakchar, 255) == 0) {
if (strncmp(word, breakchar, 1) == 0) {
line += 1; // Move down a Line
strncpy(temp, "", 1023); // Clear the tempstring
} else {
@ -132,7 +132,7 @@ SYMBOL_EXPORT void ClearToColor(struct Game* game, ALLEGRO_COLOR color) {
if (game->_priv.current_gamestate && GetFramebuffer(game) == target && al_get_parent_bitmap(target) == al_get_backbuffer(game->display)) {
al_set_target_backbuffer(game->display);
}
int x, y, w, h;
int x = 0, y = 0, w = 0, h = 0;
al_get_clipping_rectangle(&x, &y, &w, &h);
al_reset_clipping_rectangle();
al_clear_to_color(color);
@ -154,7 +154,7 @@ SYMBOL_EXPORT void ScaleBitmap(ALLEGRO_BITMAP* source, int width, int height) {
al_draw_bitmap(source, 0, 0, 0);
return;
}
int x, y;
int x = 0, y = 0;
al_lock_bitmap(al_get_target_bitmap(), ALLEGRO_PIXEL_FORMAT_ANY, ALLEGRO_LOCK_WRITEONLY);
al_lock_bitmap(source, ALLEGRO_PIXEL_FORMAT_ANY, ALLEGRO_LOCK_READONLY);
@ -183,7 +183,7 @@ SYMBOL_EXPORT void ScaleBitmap(ALLEGRO_BITMAP* source, int width, int height) {
SYMBOL_EXPORT ALLEGRO_BITMAP* LoadScaledBitmap(struct Game* game, char* filename, int width, int height) {
bool memoryscale = !strtol(GetConfigOptionDefault(game, "SuperDerpy", "GPU_scaling", "1"), NULL, 10);
ALLEGRO_BITMAP *source, *target = al_create_bitmap(width, height);
ALLEGRO_BITMAP *source = NULL, *target = al_create_bitmap(width, height);
al_set_target_bitmap(target);
al_clear_to_color(al_map_rgba(0, 0, 0, 0));
@ -305,8 +305,7 @@ SYMBOL_EXPORT void FatalErrorWithContext(struct Game* game, int line, const char
// FIXME: implement proper event loop there
#ifndef __EMSCRIPTEN__
int i;
for (i = 0; i < ALLEGRO_KEY_PAUSE; i++) {
for (int i = 0; i < ALLEGRO_KEY_PAUSE; i++) {
if (al_key_down(&kb, i)) {
done = true;
break;
@ -558,7 +557,7 @@ SYMBOL_EXPORT void PrintConsoleWithContext(struct Game* game, int line, const ch
}
SYMBOL_EXPORT void WindowCoordsToViewport(struct Game* game, int* x, int* y) {
int clipX, clipY, clipWidth, clipHeight;
int clipX = 0, clipY = 0, clipWidth = 0, clipHeight = 0;
al_get_clipping_rectangle(&clipX, &clipY, &clipWidth, &clipHeight);
*x -= clipX;
*y -= clipY;
@ -638,7 +637,7 @@ SYMBOL_EXPORT char* StrToLower(struct Game* game, const char* text) {
// FIXME: UTF-8
char *res = strdup(text), *iter = res;
while (*iter) {
*iter = tolower(*iter);
*iter = tolower((unsigned char)*iter);
iter++;
}
return AddGarbage(game, res);
@ -648,7 +647,7 @@ SYMBOL_EXPORT char* StrToUpper(struct Game* game, const char* text) {
// FIXME: UTF-8
char *res = strdup(text), *iter = res;
while (*iter) {
*iter = toupper(*iter);
*iter = toupper((unsigned char)*iter);
iter++;
}
return AddGarbage(game, res);