Re: [dev] [st] [PATCH] Correct shift amount on MODE_INSERT in tputc()

From: FRIGN <dev_AT_frign.de>
Date: Fri, 30 Jan 2015 00:41:38 +0100

On Thu, 29 Jan 2015 15:08:39 -0800
Rian Hunter <rian+suckless-dev_AT_thelig.ht> wrote:

> When MODE_INSERT is set we'd shift characters on the same
> line forward before inserting our character in tputc().
> This did not account for wide characters where width != 1.
> This patch makes it so we shift the correct amount.

> - if(IS_SET(MODE_INSERT) && term.c.x+1 < term.col)
> - memmove(gp+1, gp, (term.col - term.c.x - 1) * sizeof(Glyph));
> + if(IS_SET(MODE_INSERT) && term.c.x+width < term.col)
> + memmove(gp+width, gp, (term.col - term.c.x - 1) * sizeof(Glyph));

> In tputc(), when a character wasn't large enough to fit
> on the current line, we would call tnewline() to place it on
> the next line. Unfortunately, we weren't resetting our glyph
> pointer and this caused memory corruption when a
> wide character (width == 2) was being written. This patch
> resets our glyph pointer after calls to tnewline().

> + gp = &term.line[term.c.y][term.c.x];

> - if(term.c.x+width > term.col)
> + if(term.c.x+width > term.col) {
> tnewline(1);
> + gp = &term.line[term.c.y][term.c.x];
> + }

Hey Rian,

I tested both patches and second them. Nice work!
However, next time, please attach the patches
instead of inserting them so people with insane
mail clients can easily access them without hassle.

Happy hacking!

Cheers

FRIGN

-- 
FRIGN <dev_AT_frign.de>
Received on Fri Jan 30 2015 - 00:41:38 CET

This archive was generated by hypermail 2.3.0 : Fri Jan 30 2015 - 00:48:06 CET