JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
Fix bug in tputc writing to io file
authorRoberto E. Vargas Caballero <k0ga@shike2.com>
Tue, 25 Sep 2012 19:04:35 +0000 (21:04 +0200)
committerRoberto E. Vargas Caballero <k0ga@shike2.com>
Tue, 25 Sep 2012 19:04:35 +0000 (21:04 +0200)
If -f options is enabled then tputc() writes all the data to a file. Actual
code assumes that all the strings in 'c' parameters have always 1 byte
length, but this is not always true, because due to utf-8 encoding some
characters can have a diferent length. So it is necessary pass string length
to tputc in order it can call to write() correctly.
---
 st.c |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

st.c

diff --git a/st.c b/st.c
index 2d080e5..a0bd69f 100644 (file)
--- a/st.c
+++ b/st.c
@@ -278,7 +278,7 @@ static void tmoveto(int, int);
 static void tnew(int, int);
 static void tnewline(int);
 static void tputtab(bool);
-static void tputc(char*);
+static void tputc(char*, int);
 static void treset(void);
 static int tresize(int, int);
 static void tscrollup(int, int);
@@ -884,7 +884,7 @@ ttyread(void) {
        while(buflen >= UTF_SIZ || isfullutf8(ptr,buflen)) {
                charsize = utf8decode(ptr, &utf8c);
                utf8encode(&utf8c, s);
-               tputc(s);
+               tputc(s, charsize);
                ptr    += charsize;
                buflen -= charsize;
        }
@@ -1641,11 +1641,11 @@ tputtab(bool forward) {
 }
 
 void
-tputc(char *c) {
+tputc(char *c, int len) {
        char ascii = *c;
 
        if(iofd != -1)
-               write(iofd, c, 1);
+               write(iofd, c, len);
 
        if(term.esc & ESC_START) {
                if(term.esc & ESC_CSI) {