X-Git-Url: http://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=menu%2Fm_req_name.c;h=e5f2888ed6f2d7e6a6e1e3a3ad3b7d3f569de437;hp=01fe79e3be840e4f2b999651b1dbe7ff5620de81;hb=173dd870810c8b85baa31f9a272d15f96a8f9ff4;hpb=55ccd2b959766810cf7db8d1c4462f338ce0afc8 diff --git a/menu/m_req_name.c b/menu/m_req_name.c index 01fe79e3..e5f2888e 100644 --- a/menu/m_req_name.c +++ b/menu/m_req_name.c @@ -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 * @@ -37,7 +37,7 @@ #include "menu.priv.h" -MODULE_ID("$Id: m_req_name.c,v 1.19 2005/04/16 16:59:52 tom Exp $") +MODULE_ID("$Id: m_req_name.c,v 1.22 2012/07/21 23:27:32 tom Exp $") static const char *request_names[MAX_MENU_COMMAND - MIN_MENU_COMMAND + 1] = { @@ -99,23 +99,26 @@ menu_request_by_name(const char *str) /* because the table is so small, it doesn't really hurt to run sequentially through it. */ - unsigned int i = 0; + size_t i = 0; char buf[16]; T((T_CALLED("menu_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++) { - if (strncmp(request_names[i], buf, sizeof(buf)) == 0) + if (strcmp(request_names[i], buf) == 0) returnCode(MIN_MENU_COMMAND + (int)i); } }