aboutsummaryrefslogtreecommitdiff
path: root/st.c
diff options
context:
space:
mode:
authorAvi Halachmi (:avih) <avihpit@yahoo.com>2019-10-16 12:55:53 +0300
committerHiltjo Posthuma <hiltjo@codemadness.org>2019-11-10 22:45:54 +0100
commit2e54a21b5ae249a6bcedab9db611ea86037a018b (patch)
treeef5cc5f041826eab0da3b56b616af698705515c7 /st.c
parent289c52b7aa9b0e826bbea6f956755b3199b3ccac (diff)
downloadst-patched-2e54a21b5ae249a6bcedab9db611ea86037a018b.tar.bz2
st-patched-2e54a21b5ae249a6bcedab9db611ea86037a018b.tar.xz
st-patched-2e54a21b5ae249a6bcedab9db611ea86037a018b.zip
OSC 52 - copy to clipboard: don't limit to 382 bytes
Strings which an application sends to the terminal in OSC, DCS, etc are typically small (title, colors, etc) but one exception is OSC 52 which copies text to the clipboard, and is used for instance by tmux. Previously st cropped these strings at 512 bytes, which for OSC 52 limited the copied text to 382 bytes (remaining buffer space before base64). This made it less useful than it can be. Now it's a dynamic growing buffer. It remains allocated after use, resets to 512 when a new string starts, or leaked on exit. Resetting/deallocating the buffer right after use (at strhandle) is possible with some more code, however, it doesn't always end up used, and to cover those cases too will require even more code, so resetting only on new string is good enough for now.
Diffstat (limited to 'st.c')
-rw-r--r--st.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/st.c b/st.c
index 0c1acd4..3e48410 100644
--- a/st.c
+++ b/st.c
@@ -146,7 +146,8 @@ typedef struct {
146/* ESC type [[ [<priv>] <arg> [;]] <mode>] ESC '\' */ 146/* ESC type [[ [<priv>] <arg> [;]] <mode>] ESC '\' */
147typedef struct { 147typedef struct {
148 char type; /* ESC type ... */ 148 char type; /* ESC type ... */
149 char buf[STR_BUF_SIZ]; /* raw string */ 149 char *buf; /* allocated raw string */
150 size_t siz; /* allocation size */
150 size_t len; /* raw string length */ 151 size_t len; /* raw string length */
151 char *args[STR_ARG_SIZ]; 152 char *args[STR_ARG_SIZ];
152 int narg; /* nb of args */ 153 int narg; /* nb of args */
@@ -1948,7 +1949,10 @@ strdump(void)
1948void 1949void
1949strreset(void) 1950strreset(void)
1950{ 1951{
1951 memset(&strescseq, 0, sizeof(strescseq)); 1952 strescseq = (STREscape){
1953 .buf = xrealloc(strescseq.buf, STR_BUF_SIZ),
1954 .siz = STR_BUF_SIZ,
1955 };
1952} 1956}
1953 1957
1954void 1958void
@@ -2330,7 +2334,7 @@ tputc(Rune u)
2330 if (term.esc&ESC_DCS && strescseq.len == 0 && u == 'q') 2334 if (term.esc&ESC_DCS && strescseq.len == 0 && u == 'q')
2331 term.mode |= MODE_SIXEL; 2335 term.mode |= MODE_SIXEL;
2332 2336
2333 if (strescseq.len+len >= sizeof(strescseq.buf)) { 2337 if (strescseq.len+len >= strescseq.siz) {
2334 /* 2338 /*
2335 * Here is a bug in terminals. If the user never sends 2339 * Here is a bug in terminals. If the user never sends
2336 * some code to stop the str or esc command, then st 2340 * some code to stop the str or esc command, then st
@@ -2344,7 +2348,10 @@ tputc(Rune u)
2344 * term.esc = 0; 2348 * term.esc = 0;
2345 * strhandle(); 2349 * strhandle();
2346 */ 2350 */
2347 return; 2351 if (strescseq.siz > (SIZE_MAX - UTF_SIZ) / 2)
2352 return;
2353 strescseq.siz *= 2;
2354 strescseq.buf = xrealloc(strescseq.buf, strescseq.siz);
2348 } 2355 }
2349 2356
2350 memmove(&strescseq.buf[strescseq.len], c, len); 2357 memmove(&strescseq.buf[strescseq.len], c, len);