X-Git-Url: https://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=ncurses%2Fwidechar%2Flib_inwstr.c;h=b2fdaeac71712de4be58ff6b6cdfb7e640dd16ad;hp=76b1508beb459bea40a11693493b93157214a48c;hb=7f4b9f390624835ceb0849965a7f6ff2dcb39d00;hpb=76a479337308b4b5e749fa8c38b7b7f482998c5b diff --git a/ncurses/widechar/lib_inwstr.c b/ncurses/widechar/lib_inwstr.c index 76b1508b..b2fdaeac 100644 --- a/ncurses/widechar/lib_inwstr.c +++ b/ncurses/widechar/lib_inwstr.c @@ -1,5 +1,6 @@ /**************************************************************************** - * Copyright (c) 2002-2011,2016 Free Software Foundation, Inc. * + * Copyright 2020 Thomas E. Dickey * + * Copyright 2002-2016,2017 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 * @@ -39,7 +40,7 @@ #include -MODULE_ID("$Id: lib_inwstr.c,v 1.7 2016/05/28 23:36:34 tom Exp $") +MODULE_ID("$Id: lib_inwstr.c,v 1.9 2020/02/02 23:34:34 tom Exp $") NCURSES_EXPORT(int) winnwstr(WINDOW *win, wchar_t *wstr, int n) @@ -52,11 +53,12 @@ winnwstr(WINDOW *win, wchar_t *wstr, int n) if (win) { int row, col; int last = 0; + bool done = FALSE; getyx(win, row, col); text = win->_line[row].text; - while (count < n && count != ERR) { + while (count < n && !done && count != ERR) { if (!isWidecExt(text[col])) { int inx; @@ -66,8 +68,11 @@ winnwstr(WINDOW *win, wchar_t *wstr, int n) && ((wch = text[col].chars[inx]) != 0); ++inx) { if (count + 1 > n) { - if ((count = last) == 0) { + done = TRUE; + if (last == 0) { count = ERR; /* error if we store nothing */ + } else { + count = last; /* only store complete chars */ } break; }