From fac2d9097ef9e022e50917ac3d8a20a6748d69b8 Mon Sep 17 00:00:00 2001 From: "Diogo Franco (Kovensky)" Date: Fri, 26 Jul 2013 16:03:56 -0300 Subject: getch2: Load the "ce", "ks" and "ke" caps into a static buffer Fixes reports of printing of garbage (or anything else) other than clearing the status line to the end of line: the buffer returned by termcap_get could get moved, and if that happened then these 3 caps pointed to garbage. --- osdep/getch2.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/osdep/getch2.c b/osdep/getch2.c index 091f000cda..d31bb97ab0 100644 --- a/osdep/getch2.c +++ b/osdep/getch2.c @@ -270,7 +270,10 @@ int load_termcap(char *termtype){ #endif ensure_cap(&termcap_buf, 2048); - erase_to_end_of_line = termcap_get("ce"); + static char term_buf[64]; + char *buf_ptr = &term_buf[0]; + + erase_to_end_of_line = tgetstr("ce", &buf_ptr); screen_width = tgetnum("co"); screen_height = tgetnum("li"); @@ -279,8 +282,8 @@ int load_termcap(char *termtype){ if (screen_height < 1 || screen_height > 255) screen_height = 24; - term_smkx = termcap_get("ks"); - term_rmkx = termcap_get("ke"); + term_smkx = tgetstr("ks", &buf_ptr); + term_rmkx = tgetstr("ke", &buf_ptr); cap_key_pair keys[] = { {"kP", MP_KEY_PGUP}, {"kN", MP_KEY_PGDWN}, {"kh", MP_KEY_HOME}, {"kH", MP_KEY_END}, -- cgit v1.2.3