]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - ncurses/tinfo/read_entry.c
ncurses 6.1 - patch 20180505
[ncurses.git] / ncurses / tinfo / read_entry.c
index 92b532636b03fe0869b58451b0b31ca8f16f859d..e56c5a1ff14057a463c33c7eb7a7b9e6d7d9a654 100644 (file)
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2016,2017 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2017,2018 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -41,7 +41,7 @@
 
 #include <tic.h>
 
-MODULE_ID("$Id: read_entry.c,v 1.144 2017/10/23 21:20:06 tom Exp $")
+MODULE_ID("$Id: read_entry.c,v 1.148 2018/04/14 17:43:37 tom Exp $")
 
 #define TYPE_CALLOC(type,elts) typeCalloc(type, (unsigned)(elts))
 
@@ -384,18 +384,18 @@ _nc_read_termtype(TERMTYPE2 *ptr, char *buffer, int limit)
        int ext_bool_count = MyNumber(buf + 0);
        int ext_num_count = MyNumber(buf + 2);
        int ext_str_count = MyNumber(buf + 4);
-       int ext_str_size = MyNumber(buf + 6);
+       int ext_str_usage = MyNumber(buf + 6);
        int ext_str_limit = MyNumber(buf + 8);
        unsigned need = (unsigned) (ext_bool_count + ext_num_count + ext_str_count);
        int base = 0;
 
        if ((int) need >= (max_entry_size / 2)
-           || ext_str_size >= max_entry_size
+           || ext_str_usage >= max_entry_size
            || ext_str_limit >= max_entry_size
            || ext_bool_count < 0
            || ext_num_count < 0
            || ext_str_count < 0
-           || ext_str_size < 0
+           || ext_str_usage < 0
            || ext_str_limit < 0) {
            returnDB(TGETENT_NO);
        }
@@ -408,9 +408,15 @@ _nc_read_termtype(TERMTYPE2 *ptr, char *buffer, int limit)
        TYPE_REALLOC(NCURSES_INT2, ptr->num_Numbers, ptr->Numbers);
        TYPE_REALLOC(char *, ptr->num_Strings, ptr->Strings);
 
-       TR(TRACE_DATABASE, ("extended header is %d/%d/%d(%d:%d)",
-                           ext_bool_count, ext_num_count, ext_str_count,
-                           ext_str_size, ext_str_limit));
+       TR(TRACE_DATABASE, ("extended header: "
+                           "bool %d, "
+                           "number %d, "
+                           "string %d(%d:%d)",
+                           ext_bool_count,
+                           ext_num_count,
+                           ext_str_count,
+                           ext_str_usage,
+                           ext_str_limit));
 
        TR(TRACE_DATABASE, ("READ %d extended-booleans @%d",
                            ext_bool_count, offset));
@@ -456,8 +462,11 @@ _nc_read_termtype(TERMTYPE2 *ptr, char *buffer, int limit)
        }
 
        if ((ptr->ext_Strings = UShort(ext_str_count)) != 0) {
+           int check = (ext_bool_count + ext_num_count + ext_str_count);
+
            TR(TRACE_DATABASE,
-              ("Before computing extended-string capabilities str_count=%d, ext_str_count=%d",
+              ("Before computing extended-string capabilities "
+               "str_count=%d, ext_str_count=%d",
                str_count, ext_str_count));
            convert_strings(buf, ptr->Strings + str_count, ext_str_count,
                            ext_str_limit, ptr->ext_str_table);
@@ -466,12 +475,22 @@ _nc_read_termtype(TERMTYPE2 *ptr, char *buffer, int limit)
                                    i, i + str_count,
                                    _nc_visbuf(ptr->Strings[i + str_count])));
                ptr->Strings[i + STRCOUNT] = ptr->Strings[i + str_count];
-               if (VALID_STRING(ptr->Strings[i + STRCOUNT]))
+               if (VALID_STRING(ptr->Strings[i + STRCOUNT])) {
                    base += (int) (strlen(ptr->Strings[i + STRCOUNT]) + 1);
+                   ++check;
+               }
                TR(TRACE_DATABASE, ("... to    [%d] %s",
                                    i + STRCOUNT,
                                    _nc_visbuf(ptr->Strings[i + STRCOUNT])));
            }
+           TR(TRACE_DATABASE, ("Check table-size: %d/%d", check, ext_str_usage));
+#if 0
+           /*
+            * Phasing in a proper check will be done "later".
+            */
+           if (check != ext_str_usage)
+               returnDB(TGETENT_NO);
+#endif
        }
 
        if (need) {
@@ -818,6 +837,9 @@ _nc_read_entry2(const char *const name, char *const filename, TERMTYPE2 *const t
 {
     int code = TGETENT_NO;
 
+    if (name == 0)
+       return _nc_read_entry2("", filename, tp);
+
     _nc_SPRINTF(filename, _nc_SLIMIT(PATH_MAX)
                "%.*s", PATH_MAX - 1, name);