From 2de79ac6774087842afa97f5ca76b4837d26a713 Mon Sep 17 00:00:00 2001 From: bakkeby Date: Tue, 24 Mar 2020 14:25:10 +0100 Subject: [PATCH] OSC 52 - copy to clipboard: don't limit to 382 bytes (7a018b) --- st.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/st.c b/st.c index 4ae9bcf..894ece1 100644 --- a/st.c +++ b/st.c @@ -159,7 +159,8 @@ typedef struct { /* ESC type [[ [] [;]] ] ESC '\' */ typedef struct { char type; /* ESC type ... */ - char buf[STR_BUF_SIZ]; /* raw string */ + char *buf; /* allocated raw string */ + size_t siz; /* allocation size */ size_t len; /* raw string length */ char *args[STR_ARG_SIZ]; int narg; /* nb of args */ @@ -2073,7 +2074,10 @@ strdump(void) void strreset(void) { - memset(&strescseq, 0, sizeof(strescseq)); + strescseq = (STREscape){ + .buf = xrealloc(strescseq.buf, STR_BUF_SIZ), + .siz = STR_BUF_SIZ, + }; } void @@ -2463,7 +2467,7 @@ tputc(Rune u) if (term.esc&ESC_DCS && strescseq.len == 0 && u == 'q') term.mode |= MODE_SIXEL; - if (strescseq.len+len >= sizeof(strescseq.buf)) { + if (strescseq.len+len >= strescseq.siz) { /* * Here is a bug in terminals. If the user never sends * some code to stop the str or esc command, then st @@ -2477,7 +2481,10 @@ tputc(Rune u) * term.esc = 0; * strhandle(); */ - return; + if (strescseq.siz > (SIZE_MAX - UTF_SIZ) / 2) + return; + strescseq.siz *= 2; + strescseq.buf = xrealloc(strescseq.buf, strescseq.siz); } memmove(&strescseq.buf[strescseq.len], c, len);