/****************************************************************************
- * Copyright 2018-2020,2022 Thomas E. Dickey *
+ * Copyright 2018-2022,2023 Thomas E. Dickey *
* Copyright 2004-2009,2016 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
#include <curses.priv.h>
#include <ctype.h>
-MODULE_ID("$Id: lib_insnstr.c,v 1.8 2022/05/21 17:35:15 tom Exp $")
+MODULE_ID("$Id: lib_insnstr.c,v 1.9 2023/11/18 23:47:19 tom Exp $")
NCURSES_EXPORT(int)
winsnstr(WINDOW *win, const char *s, int n)
T((T_CALLED("winsnstr(%p,%s,%d)"), (void *) win, _nc_visbufn(s, n), n));
- if (win != 0 && str != 0) {
+ if (win != 0 && str != 0 && n != 0) {
SCREEN *sp = _nc_screen_of(win);
#if USE_WIDEC_SUPPORT
/*
* call to the wins_nwstr() function.
*/
if (sp->_screen_unicode) {
- size_t nn = (n > 0) ? (size_t) n : strlen(s);
+ size_t nn = (n >= 0) ? (size_t) n : strlen(s);
wchar_t *buffer = typeMalloc(wchar_t, nn + 1);
if (buffer != 0) {
mbstate_t state;
NCURSES_SIZE_T ox = win->_curx;
const unsigned char *cp;
- for (cp = str; (n <= 0 || (cp - str) < n) && *cp; cp++) {
+ for (cp = str; (n < 0 || (cp - str) < n) && *cp; cp++) {
_nc_insert_ch(sp, win, (chtype) UChar(*cp));
}
win->_curx = ox;