]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - form/frm_req_name.c
ncurses 5.9 - patch 20141220
[ncurses.git] / form / frm_req_name.c
index e4d5c335d8ecde9e867e0ac6943c5ce289769e46..c24db1a8a9241ca5c066efad136df67da64a5a9c 100644 (file)
@@ -1,5 +1,5 @@
 /****************************************************************************
 /****************************************************************************
- * Copyright (c) 1998-2004,2005 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2009,2012 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            *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -37,7 +37,7 @@
 
 #include "form.priv.h"
 
 
 #include "form.priv.h"
 
-MODULE_ID("$Id: frm_req_name.c,v 1.15 2005/04/16 16:59:27 tom Exp $")
+MODULE_ID("$Id: frm_req_name.c,v 1.18 2012/07/21 23:17:23 tom Exp $")
 
 static const char *request_names[MAX_FORM_COMMAND - MIN_FORM_COMMAND + 1] =
 {
 
 static const char *request_names[MAX_FORM_COMMAND - MIN_FORM_COMMAND + 1] =
 {
@@ -144,24 +144,27 @@ form_request_by_name(const char *str)
   /* because the table is so small, it doesn't really hurt
      to run sequentially through it.
    */
   /* because the table is so small, it doesn't really hurt
      to run sequentially through it.
    */
-  unsigned int i = 0;
-  char buf[16];
+  size_t i = 0;
+  char buf[16];                        /* longest name is 10 chars */
 
   T((T_CALLED("form_request_by_name(%s)"), _nc_visbuf(str)));
 
 
   T((T_CALLED("form_request_by_name(%s)"), _nc_visbuf(str)));
 
-  if (str)
+  if (str != 0 && (i = strlen(str)) != 0)
     {
     {
-      strncpy(buf, str, sizeof(buf));
-      while ((i < sizeof(buf)) && (buf[i] != '\0'))
+      if (i > sizeof(buf) - 2)
+       i = sizeof(buf) - 2;
+      memcpy(buf, str, i);
+      buf[i] = '\0';
+
+      for (i = 0; buf[i] != '\0'; ++i)
        {
        {
-         buf[i] = toupper(buf[i]);
-         i++;
+         buf[i] = (char)toupper(UChar(buf[i]));
        }
 
       for (i = 0; i < A_SIZE; i++)
        {
        }
 
       for (i = 0; i < A_SIZE; i++)
        {
-         if (strncmp(request_names[i], buf, sizeof(buf)) == 0)
-           returnCode(MIN_FORM_COMMAND + (int) i);
+         if (strcmp(request_names[i], buf) == 0)
+           returnCode(MIN_FORM_COMMAND + (int)i);
        }
     }
   RETURN(E_NO_MATCH);
        }
     }
   RETURN(E_NO_MATCH);