summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/libcurses/base/MKkeyname.awk21
1 files changed, 12 insertions, 9 deletions
diff --git a/lib/libcurses/base/MKkeyname.awk b/lib/libcurses/base/MKkeyname.awk
index 0bf3da063a6..5c45e22cc6e 100644
--- a/lib/libcurses/base/MKkeyname.awk
+++ b/lib/libcurses/base/MKkeyname.awk
@@ -1,4 +1,4 @@
-# $OpenBSD: MKkeyname.awk,v 1.3 2001/01/22 18:01:36 millert Exp $
+# $OpenBSD: MKkeyname.awk,v 1.4 2003/03/17 21:54:44 millert Exp $
# $From: MKkeyname.awk,v 1.18 2000/12/10 02:25:23 tom Exp $
##############################################################################
# Copyright (c) 1999,2000 Free Software Foundation, Inc. #
@@ -48,28 +48,31 @@ END {
print ""
print "NCURSES_EXPORT(NCURSES_CONST char *) keyname (int c)"
print "{"
- print "int i;"
- print "static char name[20];"
- print "char *p;"
+ print "\tint i;"
+ print "\tstatic char name[20];"
+ print "\tchar *p;"
+ print "\tsize_t psize;"
print ""
print "\tfor (i = 0; _nc_key_names[i].name != 0; i++)"
print "\t\tif (_nc_key_names[i].code == c)"
print "\t\t\treturn (NCURSES_CONST char *)_nc_key_names[i].name;"
print "\tif (c >= 256) return \"UNKNOWN KEY\";"
print "\tp = name;"
+ print "\tpsize = sizeof(name);"
print "\tif (c >= 128) {"
- print "\t\tstrcpy(p, \"M-\");"
+ print "\t\tstrlcpy(p, \"M-\", psize);"
print "\t\tp += 2;"
+ print "\t\tpsize -= 2;"
print "\t\tc -= 128;"
print "\t}"
print "\tif (c < 0)"
- print "\t\tsprintf(p, \"%d\", c);"
+ print "\t\tsnprintf(p, psize, \"%d\", c);"
print "\telse if (c < 32)"
- print "\t\tsprintf(p, \"^%c\", c + '@');"
+ print "\t\tsnprintf(p, psize, \"^%c\", c + '@');"
print "\telse if (c == 127)"
- print "\t\tstrcpy(p, \"^?\");"
+ print "\t\tstrlcpy(p, \"^?\", psize);"
print "\telse"
- print "\t\tsprintf(p, \"%c\", c);"
+ print "\t\tsnprintf(p, psize, \"%c\", c);"
print "\treturn (NCURSES_CONST char *)name;"
print "}"
}