From e37da61b3069f1141f4de2d84ea5d1fb120f2278 Mon Sep 17 00:00:00 2001 From: Pasi Kallinen Date: Mon, 23 May 2016 16:21:36 +0300 Subject: [PATCH] Fix valgrind complaints of uninitialized memory --- src/dungeon.c | 2 ++ src/engrave.c | 1 + src/objnam.c | 2 +- src/options.c | 1 + src/timeout.c | 1 + src/trap.c | 1 + 6 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/dungeon.c b/src/dungeon.c index 9c531e967..3a948ffac 100644 --- a/src/dungeon.c +++ b/src/dungeon.c @@ -490,6 +490,7 @@ struct proto_dungeon *pd; branch_num = find_branch(dungeons[dgn].dname, pd); new_branch = (branch *) alloc(sizeof(branch)); + (void) memset((genericptr_t)new_branch, 0, sizeof(branch)); new_branch->next = (branch *) 0; new_branch->id = branch_id++; new_branch->type = correct_branch_type(&pd->tmpbranch[branch_num]); @@ -545,6 +546,7 @@ struct proto_dungeon *pd; pd->final_lev[proto_index] = new_level = (s_level *) alloc(sizeof(s_level)); + (void) memset((genericptr_t)new_level, 0, sizeof(s_level)); /* load new level with data */ Strcpy(new_level->proto, tlevel->name); new_level->boneid = tlevel->boneschar; diff --git a/src/engrave.c b/src/engrave.c index 7c09ae530..3b5108fd8 100644 --- a/src/engrave.c +++ b/src/engrave.c @@ -388,6 +388,7 @@ xchar e_type; if ((ep = engr_at(x, y)) != 0) del_engr(ep); ep = newengr(strlen(s) + 1); + (void) memset((genericptr_t)ep, 0, sizeof(struct engr)); ep->nxt_engr = head_engr; head_engr = ep; ep->engr_x = x; diff --git a/src/objnam.c b/src/objnam.c index acf10c63e..618d1b5d7 100644 --- a/src/objnam.c +++ b/src/objnam.c @@ -2516,7 +2516,7 @@ struct obj *no_wish; int halfeaten, mntmp, contents; int islit, unlabeled, ishistoric, isdiluted, trapped; int tmp, tinv, tvariety; - int wetness, gsize; + int wetness, gsize = 0; struct fruit *f; int ftype = context.current_fruit; char fruitbuf[BUFSZ]; diff --git a/src/options.c b/src/options.c index 2a1eecade..3f35583b5 100644 --- a/src/options.c +++ b/src/options.c @@ -5496,6 +5496,7 @@ struct fruit *replace_fruit; return rnd(127); f = newfruit(); + (void) memset((genericptr_t)f, 0, sizeof(struct fruit)); copynchars(f->fname, *altname ? altname : str, PL_FSIZ - 1); f->fid = ++highest_fruit_id; /* we used to go out of our way to add it at the end of the list, diff --git a/src/timeout.c b/src/timeout.c index d4192903d..902b9befd 100644 --- a/src/timeout.c +++ b/src/timeout.c @@ -1533,6 +1533,7 @@ anything *arg; panic("start_timer"); gnu = (timer_element *) alloc(sizeof(timer_element)); + (void) memset((genericptr_t)gnu, 0, sizeof(timer_element)); gnu->next = 0; gnu->tid = timer_id++; gnu->timeout = monstermoves + when; diff --git a/src/trap.c b/src/trap.c index 6d52dce3e..6ba1aeb61 100644 --- a/src/trap.c +++ b/src/trap.c @@ -337,6 +337,7 @@ int x, y, typ; } else { oldplace = FALSE; ttmp = newtrap(); + (void) memset((genericptr_t)ttmp, 0, sizeof(struct trap)); ttmp->ntrap = 0; ttmp->tx = x; ttmp->ty = y; -- 2.40.0