]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - ncurses/tinfo/add_tries.c
ncurses 6.4 - patch 20230624
[ncurses.git] / ncurses / tinfo / add_tries.c
index 455d142edc8eefab94eb1122503c848da4a7acaa..9d215575fec02f710780bb7fac7d6eff886f8e06 100644 (file)
@@ -1,5 +1,6 @@
 /****************************************************************************
- * Copyright (c) 1998-2005,2006 Free Software Foundation, Inc.              *
+ * Copyright 2019-2020,2023 Thomas E. Dickey                                *
+ * Copyright 1998-2009,2010 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            *
@@ -38,8 +39,9 @@
 */
 
 #include <curses.priv.h>
+#include <tic.h>
 
-MODULE_ID("$Id: add_tries.c,v 1.8 2006/12/30 23:15:26 tom Exp $")
+MODULE_ID("$Id: add_tries.c,v 1.13 2023/06/24 15:36:13 tom Exp $")
 
 #define SET_TRY(dst,src) if ((dst->ch = *src++) == 128) dst->ch = '\0'
 #define CMP_TRY(a,b) ((a)? (a == b) : (b == 128))
@@ -50,8 +52,9 @@ _nc_add_to_try(TRIES ** tree, const char *str, unsigned code)
     TRIES *ptr, *savedptr;
     unsigned const char *txt = (unsigned const char *) str;
 
-    T((T_CALLED("_nc_add_to_try(%p, %s, %u)"), *tree, _nc_visbuf(str), code));
-    if (txt == 0 || *txt == '\0' || code == 0)
+    T((T_CALLED("_nc_add_to_try(%p, %s, %u)"),
+       (void *) *tree, _nc_visbuf(str), code));
+    if (!VALID_STRING(str) || *txt == '\0' || code == 0)
        returnCode(ERR);
 
     if ((*tree) != 0) {
@@ -66,7 +69,7 @@ _nc_add_to_try(TRIES ** tree, const char *str, unsigned code)
 
            if (CMP_TRY(ptr->ch, cmp)) {
                if (*(++txt) == '\0') {
-                   ptr->value = code;
+                   ptr->value = (unsigned short) code;
                    returnCode(OK);
                }
                if (ptr->child != 0)
@@ -108,6 +111,7 @@ _nc_add_to_try(TRIES ** tree, const char *str, unsigned code)
                savedptr = ptr->child;
                free(ptr);
            }
+           *tree = NULL;
            returnCode(ERR);
        }
 
@@ -115,6 +119,6 @@ _nc_add_to_try(TRIES ** tree, const char *str, unsigned code)
        ptr->value = 0;
     }
 
-    ptr->value = code;
+    ptr->value = (unsigned short) code;
     returnCode(OK);
 }