4040
4141#define MINIMAL_SIZE 20 /* minimal size for b_str */
4242
43- static buffheader_T redobuff = {{ NULL , { NUL }} , NULL , 0 , 0 };
44- static buffheader_T old_redobuff = {{ NULL , { NUL }} , NULL , 0 , 0 };
45- static buffheader_T recordbuff = {{ NULL , { NUL }} , NULL , 0 , 0 };
43+ static buffheader_T redobuff = {NULL , NULL , 0 , 0 };
44+ static buffheader_T old_redobuff = {NULL , NULL , 0 , 0 };
45+ static buffheader_T recordbuff = {NULL , NULL , 0 , 0 };
4646
4747static int typeahead_char = 0 ; /* typeahead char that's not flushed */
4848
@@ -138,12 +138,13 @@ free_buff(buffheader_T *buf)
138138{
139139 buffblock_T * p , * np ;
140140
141- for (p = buf -> bh_first . b_next ; p != NULL ; p = np )
141+ for (p = buf -> bh_first ; p != NULL ; p = np )
142142 {
143143 np = p -> b_next ;
144144 vim_free (p );
145145 }
146- buf -> bh_first .b_next = NULL ;
146+ buf -> bh_first = NULL ;
147+ buf -> bh_curr = NULL ;
147148}
148149
149150/*
@@ -159,16 +160,16 @@ get_buffcont(
159160 char_u * p = NULL ;
160161 char_u * p2 ;
161162 char_u * str ;
162- buffblock_T * bp ;
163+ buffblock_T * bp ;
163164
164165 /* compute the total length of the string */
165- for (bp = buffer -> bh_first . b_next ; bp != NULL ; bp = bp -> b_next )
166+ for (bp = buffer -> bh_first ; bp != NULL ; bp = bp -> b_next )
166167 count += (long_u )STRLEN (bp -> b_str );
167168
168169 if ((count || dozero ) && (p = lalloc (count + 1 , TRUE)) != NULL )
169170 {
170171 p2 = p ;
171- for (bp = buffer -> bh_first . b_next ; bp != NULL ; bp = bp -> b_next )
172+ for (bp = buffer -> bh_first ; bp != NULL ; bp = bp -> b_next )
172173 for (str = bp -> b_str ; * str ; )
173174 * p2 ++ = * str ++ ;
174175 * p2 = NUL ;
@@ -232,27 +233,27 @@ add_buff(
232233 long slen ) /* length of "s" or -1 */
233234{
234235 buffblock_T * p ;
235- long_u len ;
236+ long_u len ;
236237
237238 if (slen < 0 )
238239 slen = (long )STRLEN (s );
239240 if (slen == 0 ) /* don't add empty strings */
240241 return ;
241242
242- if (buf -> bh_first . b_next == NULL ) /* first add to list */
243+ if (buf -> bh_first == NULL ) /* first add to list */
243244 {
244245 buf -> bh_space = 0 ;
245- buf -> bh_curr = & ( buf -> bh_first ) ;
246+ buf -> bh_curr = NULL ;
246247 }
247248 else if (buf -> bh_curr == NULL ) /* buffer has already been read */
248249 {
249250 IEMSG (_ ("E222: Add to read buffer" ));
250251 return ;
251252 }
252253 else if (buf -> bh_index != 0 )
253- mch_memmove (buf -> bh_first . b_next -> b_str ,
254- buf -> bh_first . b_next -> b_str + buf -> bh_index ,
255- STRLEN (buf -> bh_first . b_next -> b_str + buf -> bh_index ) + 1 );
254+ mch_memmove (buf -> bh_first -> b_str ,
255+ buf -> bh_first -> b_str + buf -> bh_index ,
256+ STRLEN (buf -> bh_first -> b_str + buf -> bh_index ) + 1 );
256257 buf -> bh_index = 0 ;
257258
258259 if (buf -> bh_space >= (int )slen )
@@ -267,16 +268,25 @@ add_buff(
267268 len = MINIMAL_SIZE ;
268269 else
269270 len = slen ;
270- p = (buffblock_T * )lalloc ((long_u )(sizeof (buffblock_T ) + len ),
271- TRUE);
271+ p = (buffblock_T * )lalloc ((long_u )(sizeof (buffblock_T ) + len + 1 ),
272+ TRUE);
272273 if (p == NULL )
273274 return ; /* no space, just forget it */
274275 buf -> bh_space = (int )(len - slen );
275276 vim_strncpy (p -> b_str , s , (size_t )slen );
276277
277- p -> b_next = buf -> bh_curr -> b_next ;
278- buf -> bh_curr -> b_next = p ;
279- buf -> bh_curr = p ;
278+ if (buf -> bh_curr == NULL )
279+ {
280+ p -> b_next = NULL ;
281+ buf -> bh_first = p ;
282+ buf -> bh_curr = p ;
283+ }
284+ else
285+ {
286+ p -> b_next = buf -> bh_curr -> b_next ;
287+ buf -> bh_curr -> b_next = p ;
288+ buf -> bh_curr = p ;
289+ }
280290 }
281291 return ;
282292}
@@ -348,10 +358,10 @@ add_char_buff(buffheader_T *buf, int c)
348358}
349359
350360/* First read ahead buffer. Used for translated commands. */
351- static buffheader_T readbuf1 = {{ NULL , { NUL }} , NULL , 0 , 0 };
361+ static buffheader_T readbuf1 = {NULL , NULL , 0 , 0 };
352362
353363/* Second read ahead buffer. Used for redo. */
354- static buffheader_T readbuf2 = {{ NULL , { NUL }} , NULL , 0 , 0 };
364+ static buffheader_T readbuf2 = {NULL , NULL , 0 , 0 };
355365
356366/*
357367 * Get one byte from the read buffers. Use readbuf1 one first, use readbuf2
@@ -376,17 +386,17 @@ read_readbuf(buffheader_T *buf, int advance)
376386 char_u c ;
377387 buffblock_T * curr ;
378388
379- if (buf -> bh_first . b_next == NULL ) /* buffer is empty */
389+ if (buf -> bh_first == NULL ) /* buffer is empty */
380390 return NUL ;
381391
382- curr = buf -> bh_first . b_next ;
392+ curr = buf -> bh_first ;
383393 c = curr -> b_str [buf -> bh_index ];
384394
385395 if (advance )
386396 {
387397 if (curr -> b_str [++ buf -> bh_index ] == NUL )
388398 {
389- buf -> bh_first . b_next = curr -> b_next ;
399+ buf -> bh_first = curr -> b_next ;
390400 vim_free (curr );
391401 buf -> bh_index = 0 ;
392402 }
@@ -400,14 +410,14 @@ read_readbuf(buffheader_T *buf, int advance)
400410 static void
401411start_stuff (void )
402412{
403- if (readbuf1 .bh_first . b_next != NULL )
413+ if (readbuf1 .bh_first != NULL )
404414 {
405- readbuf1 .bh_curr = & ( readbuf1 .bh_first ) ;
415+ readbuf1 .bh_curr = readbuf1 .bh_first ;
406416 readbuf1 .bh_space = 0 ;
407417 }
408- if (readbuf2 .bh_first . b_next != NULL )
418+ if (readbuf2 .bh_first != NULL )
409419 {
410- readbuf2 .bh_curr = & ( readbuf2 .bh_first ) ;
420+ readbuf2 .bh_curr = readbuf2 .bh_first ;
411421 readbuf2 .bh_space = 0 ;
412422 }
413423}
@@ -418,8 +428,8 @@ start_stuff(void)
418428 int
419429stuff_empty (void )
420430{
421- return (readbuf1 .bh_first . b_next == NULL
422- && readbuf2 .bh_first . b_next == NULL );
431+ return (readbuf1 .bh_first == NULL
432+ && readbuf2 .bh_first == NULL );
423433}
424434
425435/*
@@ -429,7 +439,7 @@ stuff_empty(void)
429439 int
430440readbuf1_empty (void )
431441{
432- return (readbuf1 .bh_first . b_next == NULL );
442+ return (readbuf1 .bh_first == NULL );
433443}
434444
435445/*
@@ -494,7 +504,7 @@ ResetRedobuff(void)
494504 {
495505 free_buff (& old_redobuff );
496506 old_redobuff = redobuff ;
497- redobuff .bh_first . b_next = NULL ;
507+ redobuff .bh_first = NULL ;
498508 }
499509}
500510
@@ -509,7 +519,7 @@ CancelRedo(void)
509519 {
510520 free_buff (& redobuff );
511521 redobuff = old_redobuff ;
512- old_redobuff .bh_first . b_next = NULL ;
522+ old_redobuff .bh_first = NULL ;
513523 start_stuff ();
514524 while (read_readbuffers (TRUE) != NUL )
515525 ;
@@ -526,9 +536,9 @@ saveRedobuff(save_redo_T *save_redo)
526536 char_u * s ;
527537
528538 save_redo -> sr_redobuff = redobuff ;
529- redobuff .bh_first . b_next = NULL ;
539+ redobuff .bh_first = NULL ;
530540 save_redo -> sr_old_redobuff = old_redobuff ;
531- old_redobuff .bh_first . b_next = NULL ;
541+ old_redobuff .bh_first = NULL ;
532542
533543 /* Make a copy, so that ":normal ." in a function works. */
534544 s = get_buffcont (& save_redo -> sr_redobuff , FALSE);
@@ -747,9 +757,9 @@ read_redo(int init, int old_redo)
747757 if (init )
748758 {
749759 if (old_redo )
750- bp = old_redobuff .bh_first . b_next ;
760+ bp = old_redobuff .bh_first ;
751761 else
752- bp = redobuff .bh_first . b_next ;
762+ bp = redobuff .bh_first ;
753763 if (bp == NULL )
754764 return FAIL ;
755765 p = bp -> b_str ;
@@ -1372,9 +1382,9 @@ save_typeahead(tasave_T *tp)
13721382 old_char = -1 ;
13731383
13741384 tp -> save_readbuf1 = readbuf1 ;
1375- readbuf1 .bh_first . b_next = NULL ;
1385+ readbuf1 .bh_first = NULL ;
13761386 tp -> save_readbuf2 = readbuf2 ;
1377- readbuf2 .bh_first . b_next = NULL ;
1387+ readbuf2 .bh_first = NULL ;
13781388# ifdef USE_INPUT_BUF
13791389 tp -> save_inputbuf = get_input_buf ();
13801390# endif
0 commit comments