[vim/vim] Refactor getchar.c to remove calls to STRLEN() (PR #16017)

12 views
Skip to first unread message

John Marriott

unread,
Nov 8, 2024, 5:53:37 PM (4 days ago) Nov 8
to vim/vim, Subscribed

In add_buff() if buf->bh_index != 0, the string in the buffer is shortened by bh_index characters. However, when this happens bh_space was not updated to reflect the change.
In start_stuff(), bh_space is set to 0 losing it's original value. This will cause add_buff() to create a new buffer regardless of whether it is needed or not.
In the situation where bh_index != 0 and start_stuff() has not just been called, the buffer contents will be shortened but bh_space will be left with an incorrect value.

I changed add_buff() to update bh_space in the event that the string in the buffer is shortened by bh_index characters. This means if start_stuff() has just been called, add_buff() will not create a new buffer. To preserve current behaviour I added new (TRUE/FALSE) field bh_create_newblock to struct buffheader. When TRUE add_buff() will always create a new buffer. This field is set to TRUE in start_stuff().
This will keep bh_space value valid in the situation described above where bh_index != 0 and start_stuff() has not just been called.

I hope this makes sense.


You can view, comment on, or merge this pull request online at:

  https://github.com/vim/vim/pull/16017

Commit Summary

  • 1fc5714 Refactor getchar.c to remove calls to STRLEN()

File Changes

(2 files)

Patch Links:


Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/16017@github.com>

John Marriott

unread,
Nov 8, 2024, 7:09:47 PM (4 days ago) Nov 8
to vim/vim, Push

@basilisk0315 pushed 1 commit.


View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/16017/before/1fc571471540adfdd4534f7bb77cbf4d52fb65e1/after/9e736d5d12892b5d22f592c92ffc50db509c892d@github.com>

Christian Brabandt

unread,
Nov 9, 2024, 12:53:56 PM (3 days ago) Nov 9
to vim/vim, Subscribed

@chrisbra commented on this pull request.


In src/getchar.c:

> @@ -194,7 +197,9 @@ get_recorded(void)
     char_u *
 get_inserted(void)
 {
-    return get_buffcont(&redobuff, FALSE);
+    size_t  len;
+
+    return get_buffcont(&redobuff, FALSE, &len);
⬇️ Suggested change
-    return get_buffcont(&redobuff, FALSE, &len);
+    return get_buffcont(&redobuff, FALSE, NULL);

And then in get_buffcont() check whether a pointer or NULL has been given


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/16017/review/2425526550@github.com>

Christian Brabandt

unread,
Nov 9, 2024, 12:54:24 PM (3 days ago) Nov 9
to vim/vim, Subscribed

Thanks. I haven't yet checked the add_buf() changes. Need a bit more time for that.


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/16017/c2466325421@github.com>

John Marriott

unread,
Nov 10, 2024, 4:56:10 PM (2 days ago) Nov 10
to vim/vim, Push

@basilisk0315 pushed 1 commit.

  • 688e53e Allow NULL argument to get_buffcont()

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/16017/before/6b89c5aea0f401276b085b537c89b7dcdb157e96/after/688e53eb6e1cf8ef39865814cda01dda8a91ca4e@github.com>

John Marriott

unread,
Nov 10, 2024, 5:09:58 PM (2 days ago) Nov 10
to vim/vim, Subscribed

@basilisk0315 commented on this pull request.


In src/getchar.c:

> @@ -194,7 +197,9 @@ get_recorded(void)
     char_u *
 get_inserted(void)
 {
-    return get_buffcont(&redobuff, FALSE);
+    size_t  len;
+
+    return get_buffcont(&redobuff, FALSE, &len);

No worries.


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/16017/review/2425864191@github.com>

Christian Brabandt

unread,
Nov 11, 2024, 2:38:52 PM (24 hours ago) Nov 11
to vim/vim, Subscribed

Thanks. I think this is fine


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/16017/c2468897149@github.com>

Christian Brabandt

unread,
Nov 11, 2024, 2:43:44 PM (24 hours ago) Nov 11
to vim/vim, Subscribed

Closed #16017 via e7a1bbf.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/16017/issue_event/15254754547@github.com>

Reply all
Reply to author
Forward
0 new messages