diff options
author | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2025-04-13 20:44:02 +0300 |
---|---|---|
committer | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2025-04-21 20:49:37 +0300 |
commit | 93f61120ddba2093d85dbd09dff2deb42f0393e2 (patch) | |
tree | 84daad494628537c5bd2f93ef216029590ed0e01 | |
parent | 278cc757b3146be68376318999415b97220c4d92 (diff) | |
download | videoteco-fork-93f61120ddba2093d85dbd09dff2deb42f0393e2.tar.gz |
properly initialize all allocated structures
* Fixes access to uninitialized field in cmd_token, as found via Valgrind.
* Possibly other structures also aren't fully initialized, so I memset()
them as well.
-rw-r--r-- | tecbuf.c | 26 | ||||
-rw-r--r-- | tecdisp.c | 17 | ||||
-rw-r--r-- | tecparse.c | 15 | ||||
-rw-r--r-- | tecundo.c | 6 |
4 files changed, 9 insertions, 55 deletions
@@ -180,6 +180,8 @@ register int i = 0; ); if(bp == NULL) return(NULL); + + memset(bp,0,sizeof(*bp)); bp->buf_magic = MAGIC_BUFFER; bp->buf_hash = stringHash( name ); @@ -206,12 +208,6 @@ register int i = 0; if(internal_flag) bp->buffer_number = i - 1; else bp->buffer_number = i + 1; - bp->ismodified = NO; - bp->isreadonly = NO; - bp->isbackedup = NO; - bp->dot = 0; - bp->zee = 0; - /* * Create the first line buffer structure */ @@ -223,11 +219,6 @@ register int i = 0; return((struct buff_header *)NULL); }/* End IF */ bp->first_line = lbp; -/* - * Initialize the rest of the special locations - */ - bp->pos_cache.lbp = NULL; - bp->pos_cache.base = 0; /* * Link it into the list of buffer headers, in order by buffer number @@ -1244,17 +1235,13 @@ register char *cp; if(fake_line == NULL) return(FAIL); - fake_header.dot = 0; - fake_header.zee = 0; + memset(&fake_header,0,sizeof(fake_header)); fake_header.pos_cache.lbp = fake_line; - fake_header.pos_cache.base = 0; fake_header.first_line = fake_line; + memset(fake_line,0,sizeof(*fake_line)); fake_line->buffer_size = LINE_BUFFER_SIZE; fake_line->buffer = buffer; - fake_line->next_line = NULL; - fake_line->prev_line = NULL; - fake_line->format_line = NULL; while(length){ cp = fake_line->buffer; @@ -2469,6 +2456,7 @@ register struct buff_line *lbp; lbp = (struct buff_line *)tec_alloc(TYPE_C_LINE,sizeof(struct buff_line)); if(lbp == NULL) return(NULL); + memset(lbp,0,sizeof(*lbp)); if(size <= INITIAL_LINE_BUFFER_SIZE){ lbp->buffer_size = INITIAL_LINE_BUFFER_SIZE; }/* End IF */ @@ -2487,10 +2475,6 @@ register struct buff_line *lbp; return(NULL); }/* End IF */ - lbp->byte_count = 0; - lbp->next_line = NULL; - lbp->prev_line = NULL; - lbp->format_line = NULL; lbp->lin_magic = MAGIC_LINE; return(lbp); @@ -2408,6 +2408,7 @@ struct buff_header *hbp = wptr->win_buffer; tec_alloc(TYPE_C_SCREEN,sizeof(struct format_line)); if(sbp == NULL) return(NULL); + memset(sbp,0,sizeof(*sbp)); sbp->fmt_buffer_size = term_columns; sbp->fmt_buffer = (short *) tec_alloc( @@ -2495,6 +2496,7 @@ register int i; wptr = (struct window *)tec_alloc(TYPE_C_WINDOW,sizeof(struct window)); if(wptr == NULL) return(NULL); + memset(wptr,0,sizeof(*wptr)); wptr->win_label_line.fmt_buffer = (short *) tec_alloc(TYPE_C_SCRBUF,(int)(sizeof(short) * x_size)); if(wptr->win_label_line.fmt_buffer == NULL){ @@ -2503,32 +2505,21 @@ register int i; }/* End IF */ wptr->win_window_number = next_window_number++; - wptr->win_next_window = NULL; - wptr->win_buffer = NULL; /* * Initialize the xy size of the window. The y gets set to size-1 to leave * room for the label line. */ wptr->win_x_size = x_size; wptr->win_y_size = y_size - 1; - wptr->win_y_base = 0; wptr->win_y_end = wptr->win_y_base + wptr->win_y_size; /* * Initialize the label line structure. Each window has one of these in * reverse video showing which buffer is being displayed. */ - wptr->win_label_line.fmt_next_line = - wptr->win_label_line.fmt_prev_line = - wptr->win_label_line.fmt_next_alloc = - wptr->win_label_line.fmt_prev_alloc = NULL; - wptr->win_label_line.fmt_permanent = 1; - wptr->win_label_line.fmt_sequence = 0; - wptr->win_label_line.fmt_owning_buffer = NULL; wptr->win_label_line.fmt_visible_line_position = -1; wptr->win_label_line.fmt_window_ptr = wptr; /* FIX */ - wptr->win_label_line.fmt_buffer_line = NULL; wptr->win_label_line.fmt_buffer_size = x_size; for(i = 0; i < x_size; i++){ @@ -2537,10 +2528,6 @@ register int i; wptr->win_label_line.fmt_sequence = screen_sequence; - for(i = 0; i < SCREEN_MAX_LABEL_FIELDS; i++){ - wptr->win_label_field_contents[i] = NULL; - }/* End FOR */ - return(wptr); }/* End Routine */ @@ -1303,21 +1303,8 @@ register struct cmd_token *ct; * We set up the initial state to be that of an empty token, with fields * which are not set up yet set to their proper defaults. */ - ct->opcode = TOK_C_UNUSED; - ct->ctx.iarg1_flag = ct->ctx.iarg2_flag = NO; - ct->ctx.iarg1 = ct->ctx.iarg2 = 0; - ct->ctx.carg = NULL; - ct->next_token = NULL; - ct->undo_list = NULL; - ct->execute_state = 0; - ct->flags = 0; + memset(ct,0,sizeof(*ct)); - ct->prev_token = NULL; - ct->ctx.state = 0; - ct->ctx.go_flag = NO; - ct->ctx.return_state = 0; - ct->ctx.caller_token = NULL; - ct->ctx.pnest = ct->ctx.inest = ct->ctx.cnest = 0; /* * If there was an old token specified, two things must happen. First, we * have to link the new token onto the old token list. Second, we have to @@ -368,11 +368,7 @@ register struct undo_token *ut; ut = (struct undo_token *)tec_alloc(TYPE_C_UNDO,sizeof(struct undo_token)); if(ut == NULL) return(NULL); - ut->opcode = UNDO_C_UNUSED; - ut->iarg1 = 0; - ut->iarg2 = 0; - ut->carg1 = NULL; - ut->next_token = NULL; + memset(ut,0,sizeof(*ut)); if(ct != NULL){ ut->next_token = ct->undo_list; |