Module Name: src
Committed By: blymn
Date: Fri Sep 28 06:00:39 UTC 2012
Modified Files:
src/lib/libcurses: addchnstr.c
Log Message:
Truncate string to RHS of the window - SUSv2 says we should.
To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/lib/libcurses/addchnstr.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/lib/libcurses/addchnstr.c
diff -u src/lib/libcurses/addchnstr.c:1.4 src/lib/libcurses/addchnstr.c:1.5
--- src/lib/libcurses/addchnstr.c:1.4 Mon Apr 28 20:23:01 2008
+++ src/lib/libcurses/addchnstr.c Fri Sep 28 06:00:39 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: addchnstr.c,v 1.4 2008/04/28 20:23:01 martin Exp $ */
+/* $NetBSD: addchnstr.c,v 1.5 2012/09/28 06:00:39 blymn Exp $ */
/*
* Copyright (c) 2003 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: addchnstr.c,v 1.4 2008/04/28 20:23:01 martin Exp $");
+__RCSID("$NetBSD: addchnstr.c,v 1.5 2012/09/28 06:00:39 blymn Exp $");
#endif /* not lint */
#include <stdlib.h>
@@ -122,8 +122,11 @@ mvwaddchnstr(WINDOW *win, int y, int x,
/*
* waddchnstr --
* Add a string (at most n characters) to the given window
- * starting at (_cury, _curx). If n is negative, add the
- * entire string.
+ * starting at (_cury, _curx) until the end of line is reached or
+ * n characters have been added. If n is negative, add as much
+ * of the string that will fit on the current line. SUSv2 says
+ * that the addchnstr family does not wrap and strings are truncated
+ * to the RHS of the window.
*/
int
waddchnstr(WINDOW *win, const chtype *chstr, int n)
@@ -144,6 +147,10 @@ waddchnstr(WINDOW *win, const chtype *ch
else
for (chp = chstr, len = 0; *chp++; ++len);
+ /* check if string is too long for current location */
+ if (len > (win->maxx - win->curx))
+ len = win->maxx - win->curx;
+
if ((ocp = malloc(len + 1)) == NULL)
return ERR;
chp = chstr;