fix various issues discovered by scan-build

This commit is contained in:
Andrei Alexeyev 2018-07-31 11:50:04 +03:00
parent cb593cde87
commit b9262d80ab
No known key found for this signature in database
GPG key ID: 363707CD4C7FE8A4
7 changed files with 15 additions and 18 deletions

View file

@ -769,15 +769,16 @@ void process_boss(Boss **pboss) {
log_debug("Current attack [%s] is over", boss->current->name);
for(;;) {
boss->current++;
if(boss->current - boss->attacks >= boss->acount) {
if(boss->current == boss->attacks + boss->acount - 1) {
// no more attacks, die
boss->current = NULL;
boss_death(pboss);
break;
}
boss->current++;
assert(boss->current != NULL);
if(boss->current->type == AT_Immediate) {
boss->current->starttime = global.frames;
boss->current->rule(boss, EVENT_BIRTH);

View file

@ -91,7 +91,7 @@ static EventPriority real_priority(EventPriority prio) {
}
static EventHandlerContainer* ehandler_wrap_container(EventHandler *handler) {
EventHandlerContainer *c = calloc(1, sizeof(ListContainer));
EventHandlerContainer *c = calloc(1, sizeof(*c));
c->handler = handler;
return c;
}

View file

@ -60,7 +60,7 @@ ObjectPool *objpool_alloc(size_t obj_size, size_t max_objects, const char *tag)
}
static char *objpool_add_extent(ObjectPool *pool) {
pool->extents = realloc(pool->extents, (++pool->num_extents) * sizeof(pool->extents));
pool->extents = realloc(pool->extents, (++pool->num_extents) * sizeof(*pool->extents));
char *extent = pool->extents[pool->num_extents - 1] = calloc(pool->max_objects, pool->size_of_object);
objpool_register_objects(pool, extent);
return extent;

View file

@ -246,8 +246,7 @@ static void youmu_particle_slice_draw(Projectile *p, int t) {
r_mat_pop();
double slicelen = 500;
f = sqrt(f);
complex slicepos=p->pos-(tt>0.1)*slicelen*I*cexp(I*p->angle)*(5*pow(tt-0.1,1.1)-0.5);
complex slicepos = p->pos-(tt>0.1)*slicelen*I*cexp(I*p->angle)*(5*pow(tt-0.1,1.1)-0.5);
draw_sprite_batched_p(creal(slicepos), cimag(slicepos), aniplayer_get_frame(&global.plr.ani));
}

View file

@ -261,7 +261,7 @@ void* load_animation_end(void *opaque, const char *filename, uint flags) {
log_warn("Animation frame '%s' not found but @sprite_count was %d",buf,ani->sprite_count);
unload_animation(ani);
ani = NULL;
break;
goto done;
}
ani->sprites[i] = res->data;
@ -274,6 +274,7 @@ void* load_animation_end(void *opaque, const char *filename, uint flags) {
ani = NULL;
}
done:
free(data->basename);
free(data);

View file

@ -498,14 +498,10 @@ static Glyph* get_glyph(Font *fnt, charcode_t cp) {
log_debug("Font has no glyph for charcode 0x%08lx", cp);
glyph = get_glyph(fnt, UNICODE_UNKNOWN);
ofs = glyph ? (ptrdiff_t)(glyph - fnt->glyphs) : -1;
} else {
if(ht_lookup(&fnt->ftindex_to_glyph_ofs, ft_index, &ofs)) {
glyph = fnt->glyphs + ofs;
} else {
glyph = load_glyph(fnt, ft_index, &fnt->spritesheets);
ofs = glyph ? (ptrdiff_t)(glyph - fnt->glyphs) : -1;
ht_set(&fnt->ftindex_to_glyph_ofs, ft_index, ofs);
}
} else if(!ht_lookup(&fnt->ftindex_to_glyph_ofs, ft_index, &ofs)) {
glyph = load_glyph(fnt, ft_index, &fnt->spritesheets);
ofs = glyph ? (ptrdiff_t)(glyph - fnt->glyphs) : -1;
ht_set(&fnt->ftindex_to_glyph_ofs, ft_index, ofs);
}
ht_set(&fnt->charcodes_to_glyph_ofs, cp, ofs);

View file

@ -163,13 +163,13 @@ bool parse_bool(const char *str, bool fallback) {
static const char *true_vals[] = { "on", "yes", "true", NULL };
static const char *false_vals[] = { "off", "no", "false", NULL };
for(const char **v = true_vals; v; ++v) {
for(const char **v = true_vals; *v; ++v) {
if(!SDL_strcasecmp(buf, *v)) {
return true;
}
}
for(const char **v = false_vals; v; ++v) {
for(const char **v = false_vals; *v; ++v) {
if(!SDL_strcasecmp(buf, *v)) {
return false;
}