tgetent corrupts stack (cured); Small tgetent program crashes gdb

Steven Pemberton Steven.Pemberton@cwi.nl
Sun Feb 18 04:14:00 GMT 2001


I had a program where tgetent was corrupting the stack. While trying to
track down the problem, I managed to crash gdb.

This is a report of two problems.

1) 'info tgetent' says that 'the [termcap] emulation ignores the buffer
pointer bp' (the first param of tgetent). However, this isn't true: the
buffer really does get used, and it has to be at least 1038 bytes long (the
'traditional' size for the tgetent buffer is 1024 bytes), otherwise the
stack gets corrupted.

2) with this tiny program, if I debug it with gdb, and stop before the last
line (i=t) and try to look at the contents of 'buf', gdb crashes. With a
value of 1024, or 1536 for the buffer size, gdb doesn't seem to crash.

#include <stdlib.h>
#include <curses.h>

main() {
  char *s; int t, i;
  char buf[2048];
  s= getenv("TERM");
  t= tgetent(buf, s);
  i=t;
}

Steven Pemberton
CWI, Amsterdam
(Not a regular reader of this list, so Cc me if you want a reply)



More information about the Cygwin mailing list