ncurses 5.9 - patch 20130727
[ncurses.git] / ncurses / tinfo / write_entry.c
index 9fdfe59d97113c955b65478a772a9e725f15822f..f7ae96fb584f5ee7305c7a2904b7c795080717a6 100644 (file)
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2011,2012 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2012,2013 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            *
@@ -47,7 +47,7 @@
 #define TRACE_OUT(p)           /*nothing */
 #endif
 
-MODULE_ID("$Id: write_entry.c,v 1.86 2012/06/16 16:59:05 tom Exp $")
+MODULE_ID("$Id: write_entry.c,v 1.88 2013/07/27 15:52:18 tom Exp $")
 
 static int total_written;
 
@@ -273,16 +273,21 @@ _nc_write_entry(TERMTYPE *const tp)
     char name_list[MAX_TERMINFO_LENGTH];
     char *first_name, *other_names;
     char *ptr;
+    const char *term_names = tp->term_names;
+    size_t name_size = strlen(term_names);
 
-    assert(strlen(tp->term_names) != 0);
-    assert(strlen(tp->term_names) < sizeof(name_list));
+    if (name_size == 0) {
+       _nc_syserr_abort("no terminal name found.");
+    } else if (name_size >= sizeof(name_list) - 1) {
+       _nc_syserr_abort("terminal name too long: %s", term_names);
+    }
 
-    _nc_STRCPY(name_list, tp->term_names, sizeof(name_list));
+    _nc_STRCPY(name_list, term_names, sizeof(name_list));
     DEBUG(7, ("Name list = '%s'", name_list));
 
     first_name = name_list;
 
-    ptr = &name_list[strlen(name_list) - 1];
+    ptr = &name_list[name_size - 1];
     other_names = ptr + 1;
 
     while (ptr > name_list && *ptr != '|')
@@ -316,8 +321,8 @@ _nc_write_entry(TERMTYPE *const tp)
            buffer[0] = 0;
 
            memset(&key, 0, sizeof(key));
-           key.data = tp->term_names;
-           key.size = strlen(tp->term_names);
+           key.data = term_names;
+           key.size = name_size;
 
            memset(&data, 0, sizeof(data));
            data.data = buffer;
@@ -331,9 +336,9 @@ _nc_write_entry(TERMTYPE *const tp)
            key.size = strlen(name_list);
 
            _nc_STRCPY(buffer + 1,
-                      tp->term_names,
+                      term_names,
                       sizeof(buffer) - 1);
-           data.size = strlen(tp->term_names) + 1;
+           data.size = name_size + 1;
 
            _nc_db_put(capdb, &key, &data);