mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
vim-patch:8.0.1723: using one item array size declaration is misleading
Problem: Using one item array size declaration is misleading.
Solution: Instead of using "[1]" and actually using a larger array, use
"[]". This is to verify that this C99 feature works for all
compilers.
f3a411783c
The following patch is N/A because Neovim requires C99.
vim-patch:8.0.1735: flexible array member feature not supported by HP-UX
This commit is contained in:
parent
352d5a9713
commit
315076a26d
@ -133,14 +133,14 @@ typedef struct buffheader buffheader_T;
|
||||
*/
|
||||
struct buffblock {
|
||||
buffblock_T *b_next; // pointer to next buffblock
|
||||
char_u b_str[1]; // contents (actually longer)
|
||||
char_u b_str[]; // contents (flexible array)
|
||||
};
|
||||
|
||||
/*
|
||||
* header used for the stuff buffer and the redo buffer
|
||||
*/
|
||||
struct buffheader {
|
||||
buffblock_T bh_first; // first (dummy) block of list
|
||||
buffblock_T *bh_first; // first block of the list
|
||||
buffblock_T *bh_curr; // buffblock for appending
|
||||
size_t bh_index; // index for reading
|
||||
size_t bh_space; // space in bh_curr for appending
|
||||
|
@ -77,15 +77,15 @@ FileDescriptor *scriptin[NSCRIPT] = { NULL };
|
||||
|
||||
#define MINIMAL_SIZE 20 /* minimal size for b_str */
|
||||
|
||||
static buffheader_T redobuff = { { NULL, { NUL } }, NULL, 0, 0 };
|
||||
static buffheader_T old_redobuff = { { NULL, { NUL } }, NULL, 0, 0 };
|
||||
static buffheader_T recordbuff = { { NULL, { NUL } }, NULL, 0, 0 };
|
||||
static buffheader_T redobuff = { NULL, NULL, 0, 0 };
|
||||
static buffheader_T old_redobuff = { NULL, NULL, 0, 0 };
|
||||
static buffheader_T recordbuff = { NULL, NULL, 0, 0 };
|
||||
|
||||
// First read ahead buffer. Used for translated commands.
|
||||
static buffheader_T readbuf1 = {{NULL, {NUL}}, NULL, 0, 0};
|
||||
static buffheader_T readbuf1 = { NULL, NULL, 0, 0 };
|
||||
|
||||
// Second read ahead buffer. Used for redo.
|
||||
static buffheader_T readbuf2 = {{NULL, {NUL}}, NULL, 0, 0};
|
||||
static buffheader_T readbuf2 = { NULL, NULL, 0, 0 };
|
||||
|
||||
static int typeahead_char = 0; /* typeahead char that's not flushed */
|
||||
|
||||
@ -163,11 +163,12 @@ void free_buff(buffheader_T *buf)
|
||||
{
|
||||
buffblock_T *p, *np;
|
||||
|
||||
for (p = buf->bh_first.b_next; p != NULL; p = np) {
|
||||
for (p = buf->bh_first; p != NULL; p = np) {
|
||||
np = p->b_next;
|
||||
xfree(p);
|
||||
}
|
||||
buf->bh_first.b_next = NULL;
|
||||
buf->bh_first = NULL;
|
||||
buf->bh_curr = NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -181,18 +182,21 @@ static char_u *get_buffcont(buffheader_T *buffer,
|
||||
size_t count = 0;
|
||||
char_u *p = NULL;
|
||||
char_u *p2;
|
||||
char_u *str;
|
||||
|
||||
/* compute the total length of the string */
|
||||
for (buffblock_T *bp = buffer->bh_first.b_next; bp != NULL; bp = bp->b_next)
|
||||
// compute the total length of the string
|
||||
for (const buffblock_T *bp = buffer->bh_first; bp != NULL; bp = bp->b_next) {
|
||||
count += STRLEN(bp->b_str);
|
||||
}
|
||||
|
||||
if (count || dozero) {
|
||||
p = xmalloc(count + 1);
|
||||
p2 = p;
|
||||
for (buffblock_T *bp = buffer->bh_first.b_next; bp != NULL; bp = bp->b_next)
|
||||
for (str = bp->b_str; *str; )
|
||||
for (const buffblock_T *bp = buffer->bh_first;
|
||||
bp != NULL; bp = bp->b_next) {
|
||||
for (const char_u *str = bp->b_str; *str;) {
|
||||
*p2++ = *str++;
|
||||
}
|
||||
}
|
||||
*p2 = NUL;
|
||||
}
|
||||
return p;
|
||||
@ -257,16 +261,16 @@ static void add_buff(buffheader_T *const buf, const char *const s,
|
||||
return;
|
||||
}
|
||||
|
||||
if (buf->bh_first.b_next == NULL) { // first add to list
|
||||
if (buf->bh_first == NULL) { // first add to list
|
||||
buf->bh_space = 0;
|
||||
buf->bh_curr = &(buf->bh_first);
|
||||
buf->bh_curr = NULL;
|
||||
} else if (buf->bh_curr == NULL) { // buffer has already been read
|
||||
IEMSG(_("E222: Add to read buffer"));
|
||||
return;
|
||||
} else if (buf->bh_index != 0) {
|
||||
memmove(buf->bh_first.b_next->b_str,
|
||||
buf->bh_first.b_next->b_str + buf->bh_index,
|
||||
STRLEN(buf->bh_first.b_next->b_str + buf->bh_index) + 1);
|
||||
memmove(buf->bh_first->b_str,
|
||||
buf->bh_first->b_str + buf->bh_index,
|
||||
STRLEN(buf->bh_first->b_str + buf->bh_index) + 1);
|
||||
}
|
||||
buf->bh_index = 0;
|
||||
|
||||
@ -281,14 +285,20 @@ static void add_buff(buffheader_T *const buf, const char *const s,
|
||||
} else {
|
||||
len = (size_t)slen;
|
||||
}
|
||||
buffblock_T *p = xmalloc(sizeof(buffblock_T) + len);
|
||||
buffblock_T *p = xmalloc(sizeof(buffblock_T) + len + 1);
|
||||
buf->bh_space = len - (size_t)slen;
|
||||
STRLCPY(p->b_str, s, slen + 1);
|
||||
|
||||
if (buf->bh_curr == NULL) {
|
||||
p->b_next = NULL;
|
||||
buf->bh_first = p;
|
||||
buf->bh_curr = p;
|
||||
} else {
|
||||
p->b_next = buf->bh_curr->b_next;
|
||||
buf->bh_curr->b_next = p;
|
||||
buf->bh_curr = p;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@ -356,17 +366,17 @@ static int read_readbuffers(int advance)
|
||||
static int read_readbuf(buffheader_T *buf, int advance)
|
||||
{
|
||||
char_u c;
|
||||
buffblock_T *curr;
|
||||
|
||||
if (buf->bh_first.b_next == NULL) /* buffer is empty */
|
||||
if (buf->bh_first == NULL) { // buffer is empty
|
||||
return NUL;
|
||||
}
|
||||
|
||||
curr = buf->bh_first.b_next;
|
||||
buffblock_T *const curr = buf->bh_first;
|
||||
c = curr->b_str[buf->bh_index];
|
||||
|
||||
if (advance) {
|
||||
if (curr->b_str[++buf->bh_index] == NUL) {
|
||||
buf->bh_first.b_next = curr->b_next;
|
||||
buf->bh_first = curr->b_next;
|
||||
xfree(curr);
|
||||
buf->bh_index = 0;
|
||||
}
|
||||
@ -379,12 +389,12 @@ static int read_readbuf(buffheader_T *buf, int advance)
|
||||
*/
|
||||
static void start_stuff(void)
|
||||
{
|
||||
if (readbuf1.bh_first.b_next != NULL) {
|
||||
readbuf1.bh_curr = &(readbuf1.bh_first);
|
||||
if (readbuf1.bh_first != NULL) {
|
||||
readbuf1.bh_curr = readbuf1.bh_first;
|
||||
readbuf1.bh_space = 0;
|
||||
}
|
||||
if (readbuf2.bh_first.b_next != NULL) {
|
||||
readbuf2.bh_curr = &(readbuf2.bh_first);
|
||||
if (readbuf2.bh_first != NULL) {
|
||||
readbuf2.bh_curr = readbuf2.bh_first;
|
||||
readbuf2.bh_space = 0;
|
||||
}
|
||||
}
|
||||
@ -394,7 +404,8 @@ static void start_stuff(void)
|
||||
*/
|
||||
int stuff_empty(void)
|
||||
{
|
||||
return (readbuf1.bh_first.b_next == NULL && readbuf2.bh_first.b_next == NULL);
|
||||
return (readbuf1.bh_first == NULL
|
||||
&& readbuf2.bh_first == NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -403,7 +414,7 @@ int stuff_empty(void)
|
||||
*/
|
||||
int readbuf1_empty(void)
|
||||
{
|
||||
return (readbuf1.bh_first.b_next == NULL);
|
||||
return (readbuf1.bh_first == NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -461,7 +472,7 @@ void ResetRedobuff(void)
|
||||
if (!block_redo) {
|
||||
free_buff(&old_redobuff);
|
||||
old_redobuff = redobuff;
|
||||
redobuff.bh_first.b_next = NULL;
|
||||
redobuff.bh_first = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
@ -474,7 +485,7 @@ void CancelRedo(void)
|
||||
if (!block_redo) {
|
||||
free_buff(&redobuff);
|
||||
redobuff = old_redobuff;
|
||||
old_redobuff.bh_first.b_next = NULL;
|
||||
old_redobuff.bh_first = NULL;
|
||||
start_stuff();
|
||||
while (read_readbuffers(TRUE) != NUL) {
|
||||
}
|
||||
@ -486,9 +497,9 @@ void CancelRedo(void)
|
||||
void saveRedobuff(save_redo_T *save_redo)
|
||||
{
|
||||
save_redo->sr_redobuff = redobuff;
|
||||
redobuff.bh_first.b_next = NULL;
|
||||
redobuff.bh_first = NULL;
|
||||
save_redo->sr_old_redobuff = old_redobuff;
|
||||
old_redobuff.bh_first.b_next = NULL;
|
||||
old_redobuff.bh_first = NULL;
|
||||
|
||||
// Make a copy, so that ":normal ." in a function works.
|
||||
char *const s = (char *)get_buffcont(&save_redo->sr_redobuff, false);
|
||||
@ -668,12 +679,10 @@ static int read_redo(bool init, bool old_redo)
|
||||
int i;
|
||||
|
||||
if (init) {
|
||||
if (old_redo)
|
||||
bp = old_redobuff.bh_first.b_next;
|
||||
else
|
||||
bp = redobuff.bh_first.b_next;
|
||||
if (bp == NULL)
|
||||
bp = old_redo ? old_redobuff.bh_first : redobuff.bh_first;
|
||||
if (bp == NULL) {
|
||||
return FAIL;
|
||||
}
|
||||
p = bp->b_str;
|
||||
return OK;
|
||||
}
|
||||
@ -1206,9 +1215,9 @@ void save_typeahead(tasave_T *tp)
|
||||
old_char = -1;
|
||||
|
||||
tp->save_readbuf1 = readbuf1;
|
||||
readbuf1.bh_first.b_next = NULL;
|
||||
readbuf1.bh_first = NULL;
|
||||
tp->save_readbuf2 = readbuf2;
|
||||
readbuf2.bh_first.b_next = NULL;
|
||||
readbuf2.bh_first = NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
|
Loading…
Reference in New Issue
Block a user