diff -ru src/termcap.c src.fixed/termcap.c
--- src/termcap.c	2002-02-25 18:59:21.000000000 +0100
+++ src.fixed/termcap.c	2012-01-09 11:04:54.000000000 +0100
@@ -460,6 +460,7 @@
   char *tcenv = NULL;		/* TERMCAP value, if it contains :tc=.  */
   char *indirect = NULL;	/* Terminal type in :tc= in TERMCAP value.  */
   int filep;
+  char *term_name;
 
 #ifdef INTERNAL_TERMINAL
   /* For the internal terminal we don't want to read any termcap file,
@@ -500,7 +501,8 @@
      it is the entry itself, but only if
      the name the caller requested matches the TERM variable.  */
 
-  if (termcap_name && !filep && !strcmp (name, getenv ("TERM")))
+  term_name = getenv("TERM");
+  if (termcap_name && !filep && term_name && !strcmp (name, term_name))
     {
       indirect = tgetst1 (find_capability (termcap_name, "tc"), (char **) 0);
       if (!indirect)
