Enabled conversion warnings in GCC

This commit is contained in:
Linus Probert 2018-02-22 09:44:27 +01:00
parent c02d674618
commit 9fec8fcb1f
10 changed files with 29 additions and 27 deletions

2
.vimrc
View File

@ -3,4 +3,4 @@ nnoremap <F2> :Make clean<cr>
nnoremap <F3> :Make test<cr>
nnoremap <F4> :!./build/breakhack<cr>
let g:syntastic_c_include_dirs = [ 'build' ]
let g:syntastic_c_include_dirs = [ 'build', '/usr/include/SDL2' ]

View File

@ -43,6 +43,7 @@ if (NOT WIN32)
-Wpointer-arith -Wcast-qual
-Wstrict-prototypes
-Wmissing-prototypes
-Wconversion -Wno-sign-conversion
)
endif (NOT WIN32)

View File

@ -245,10 +245,11 @@ update_xp_bar(Gui *gui, ExperienceData *data)
unsigned int xp_from_levelup = data->current - data->previousLevel;
unsigned int xp_required_from_last_level = data->nextLevel - data->previousLevel;
float xp_step = ((float)xp_required_from_last_level) / 32; // 4 * 8
float xp_current_step = xp_from_levelup / xp_step;
float xp_current_step = (float) xp_from_levelup / xp_step;
unsigned int partial_xp_block = ((unsigned int) xp_current_step) % 4;
unsigned int full_xp_blocks = (unsigned int) ((xp_current_step - partial_xp_block) / 4);
unsigned int full_xp_blocks =
(unsigned int) ((xp_current_step - (float) partial_xp_block) / 4);
LinkedList *xp_bars = gui->xp_bar;
unsigned int i = 0;

View File

@ -35,7 +35,7 @@ ht_create(unsigned int size)
table = ec_malloc(sizeof(Hashtable));
table->size = size;
table->entries = ec_malloc(sizeof(Entry) * size);
table->entries = ec_malloc((unsigned int) sizeof(Entry) * size);
for (i = 0; i < size; ++i) {
table->entries[i] = NULL;
@ -73,12 +73,12 @@ entry_create(const char *key, void *value)
void
ht_set(Hashtable *table, const char *key, void *val)
{
int hashkey = 0;
unsigned int hashkey = 0;
Entry *newEntry = NULL;
Entry *next;
Entry *last = NULL;
hashkey = hash(table, key);
hashkey = hash(table, key);
next = table->entries[hashkey];
@ -117,7 +117,7 @@ ht_set(Hashtable *table, const char *key, void *val)
void*
ht_get(Hashtable *table, const char *key)
{
int hashkey = 0;
unsigned int hashkey = 0;
Entry *entry;
hashkey = hash(table, key);

View File

@ -236,7 +236,7 @@ createMenu(Menu **menu, struct MENU_ITEM menu_items[], unsigned int size)
*menu = menu_create();
for (unsigned int i = 0; i < size; ++i) {
int hcenter;
unsigned int hcenter;
Sprite *s1 = sprite_create();
sprite_load_text_texture(s1, "assets/GUI/SDS_8x8.ttf", 0, 25);
@ -244,7 +244,7 @@ createMenu(Menu **menu, struct MENU_ITEM menu_items[], unsigned int size)
C_MENU_DEFAULT, gRenderer);
hcenter = (SCREEN_WIDTH/2) - (s1->textures[0]->dim.width/2);
s1->pos = (Position) { hcenter, 200 + (i*50) };
s1->pos = (Position) { (int) hcenter, (int) 200 + (i*50) };
s1->fixed = true;
Sprite *s2 = sprite_create();
@ -252,7 +252,7 @@ createMenu(Menu **menu, struct MENU_ITEM menu_items[], unsigned int size)
texture_load_from_text(s2->textures[0], menu_items[i].label,
C_MENU_HOVER, gRenderer);
s2->pos = (Position) { hcenter, 200 + (i*50) };
s2->pos = (Position) { (int) hcenter, (int) 200 + (i*50) };
s2->fixed = true;
menu_item_add(*menu, s1, s2, menu_items[i].callback);
@ -562,7 +562,7 @@ void run(void)
break;
}
int ticks = timer_get_ticks(fpsTimer);
unsigned int ticks = timer_get_ticks(fpsTimer);
if (ticks < 1000/60)
SDL_Delay((1000/60) - ticks);
timer_stop(fpsTimer);
@ -572,7 +572,7 @@ void run(void)
else {
oldTime = currentTime;
currentTime = SDL_GetTicks();
deltaTime = (currentTime - oldTime) / 1000.0;
deltaTime = (float) ((currentTime - oldTime) / 1000.0);
}
}

View File

@ -185,11 +185,11 @@ lua_checkstats(lua_State *L, int index)
lua_getfield(L, tableIndex, "def");
lua_getfield(L, tableIndex, "speed");
int hp = luaL_checkinteger(L, -5);
int dmg = luaL_checkinteger(L, -4);
int atk = luaL_checkinteger(L, -3);
int def = luaL_checkinteger(L, -2);
int speed = luaL_checkinteger(L, -1);
int hp = (int) luaL_checkinteger(L, -5);
int dmg = (int) luaL_checkinteger(L, -4);
int atk = (int) luaL_checkinteger(L, -3);
int def = (int) luaL_checkinteger(L, -2);
int speed = (int) luaL_checkinteger(L, -1);
// Reset the stack
lua_pop(L, 6);

View File

@ -84,7 +84,7 @@ particle_engine_bloodspray(Position pos, Dimension dim, unsigned int count)
p = ec_malloc(sizeof(Particle));
p->pos = (Position) { x, y };
p->velocity = (Vector2d) { xv, yv };
p->velocity = (Vector2d) { (float) xv, (float) yv };
p->movetime = mt;
p->lifetime = lt;
p->dim = (Dimension) { w, h };
@ -120,11 +120,11 @@ create_explosion(Position pos, Dimension dim, size_t c_count, ...)
p = ec_malloc(sizeof(Particle));
p->pos = (Position) { x, y };
p->velocity = (Vector2d) { xv, yv };
p->velocity = (Vector2d) { (float) xv, (float) yv };
p->movetime = lt;
p->lifetime = lt;
p->dim = (Dimension) { 2, 2 };
p->color = colors[get_random(c_count-1)];
p->color = colors[get_random((unsigned int) c_count-1)];
linkedlist_append(&engine->particles, p);
}
}
@ -154,8 +154,8 @@ move_particle(Particle *particle, float deltaTime)
if (!particle->movetime)
return;
particle->pos.x += particle->velocity.x * deltaTime;
particle->pos.y += particle->velocity.y * deltaTime;
particle->pos.x += (int) (particle->velocity.x * deltaTime);
particle->pos.y += (int) (particle->velocity.y * deltaTime);
}
void

View File

@ -239,7 +239,7 @@ roommatrix_render_lightmap(RoomMatrix *matrix, Camera *cam)
};
SDL_SetRenderDrawColor(cam->renderer,
0, 0, 0, light);
0, 0, 0, (Uint8) light);
SDL_RenderFillRect(cam->renderer, &box);
#ifdef LIGHTMAPDEBUG

View File

@ -134,7 +134,7 @@ fatal(const char *fmt, ...)
}
void
*ec_malloc(unsigned int size)
*ec_malloc(unsigned long size)
{
void *ptr;
ptr = malloc(size);
@ -170,10 +170,10 @@ to_lower(const char *str)
char *lcstr;
unsigned int i;
lcstr = ec_malloc((strlen(str) + 1) * sizeof(char));
lcstr = ec_malloc(((unsigned int) strlen(str) + 1) * sizeof(char));
for (i = 0; i < strlen(str); ++i) {
lcstr[i] = tolower(str[i]);
lcstr[i] = (char) tolower(str[i]);
}
lcstr[i] = '\0';

View File

@ -32,7 +32,7 @@ void
info(const char *fmt, ...);
void *
ec_malloc(unsigned int size);
ec_malloc(unsigned long size);
void
m_strcpy(char *dest, size_t destsz, char *src);