X-Git-Url: https://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=ncurses%2Fbase%2Flib_insnstr.c;h=8ee26a8091c1ef5d20140d457ed42571072fb920;hp=d3cf1bd554f474b799959e4f9f5cff2043d5d014;hb=b86393354bb86154b7b860989e5ed8655611d30b;hpb=bcdff1f4b369c01b695ca2b73e9aaac54f9c4526 diff --git a/ncurses/base/lib_insnstr.c b/ncurses/base/lib_insnstr.c index d3cf1bd5..8ee26a80 100644 --- a/ncurses/base/lib_insnstr.c +++ b/ncurses/base/lib_insnstr.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 2004-2009,2016 Free Software Foundation, Inc. * + * Copyright (c) 2004-2016,2018 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 * @@ -40,16 +40,13 @@ #include #include -MODULE_ID("$Id: lib_insnstr.c,v 1.4 2016/02/20 21:22:46 tom Exp $") +MODULE_ID("$Id: lib_insnstr.c,v 1.6 2018/03/10 20:13:59 Gyorgy.Jeney Exp $") NCURSES_EXPORT(int) winsnstr(WINDOW *win, const char *s, int n) { int code = ERR; - NCURSES_SIZE_T oy; - NCURSES_SIZE_T ox; const unsigned char *str = (const unsigned char *) s; - const unsigned char *cp; T((T_CALLED("winsnstr(%p,%s,%d)"), (void *) win, _nc_visbufn(s, n), n)); @@ -80,10 +77,11 @@ winsnstr(WINDOW *win, const char *s, int n) if (code == ERR) #endif { + NCURSES_SIZE_T oy = win->_cury; + NCURSES_SIZE_T ox = win->_curx; + const unsigned char *cp; - oy = win->_cury; - ox = win->_curx; - for (cp = str; *cp && (n <= 0 || (cp - str) < n); cp++) { + for (cp = str; (n <= 0 || (cp - str) < n) && *cp; cp++) { _nc_insert_ch(sp, win, (chtype) UChar(*cp)); } win->_curx = ox;