CVS commit: src/dist/nvi/common

2013-11-18 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Mon Nov 18 20:03:02 UTC 2013

Modified Files:
src/dist/nvi/common: api.c

Log Message:
Change content of string, don't overwrite the newly allocated pointer.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/dist/nvi/common/api.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/dist/nvi/common/api.c
diff -u src/dist/nvi/common/api.c:1.2 src/dist/nvi/common/api.c:1.3
--- src/dist/nvi/common/api.c:1.2	Fri Dec  5 22:51:42 2008
+++ src/dist/nvi/common/api.c	Mon Nov 18 20:03:02 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: api.c,v 1.2 2008/12/05 22:51:42 christos Exp $ */
+/*	$NetBSD: api.c,v 1.3 2013/11/18 20:03:02 joerg Exp $ */
 
 /*-
  * Copyright (c) 1992, 1993, 1994
@@ -438,7 +438,7 @@ api_opts_get(SCR *sp, const CHAR_T *name
 	case OPT_STR:
 		if (O_STR(sp, offset) == NULL) {
 			MALLOC_RET(sp, *value, char *, 2);
-			value[0] = '\0';
+			value[0][0] = '\0';
 		} else {
 			MALLOC_RET(sp,
 			*value, char *, strlen(O_STR(sp, offset)) + 1);



CVS commit: src/dist/nvi/common

2013-01-23 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed Jan 23 18:51:51 UTC 2013

Modified Files:
src/dist/nvi/common: conv.c

Log Message:
It is ridiculous to truncate files on character conversions without
warning and a chance for recovery. This patch sets the handler to
copy the character, clear the error and proceed instead of bailing
out.

To replicate:
- unset LANG
- Create a file that has ~1000 lines. Put a single bad character
- '\344' in it, around 2/3rds of the file down. Save it.
- export LANG=en_US.UTF-8
- edit the file. Notice there is no error for input conversion,
  since nvi reads the file opportunistically.
- :w Boom, the file is truncated.

Alternatively, you can put that character in the first line of the file,
and watch the fireworks. If you like to restore the previous behavior
compile with -DERROR_ON_CONVERT

XXX: Pullup to 6, 5 etc.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/dist/nvi/common/conv.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/dist/nvi/common/conv.c
diff -u src/dist/nvi/common/conv.c:1.6 src/dist/nvi/common/conv.c:1.7
--- src/dist/nvi/common/conv.c:1.6	Sat Jan 17 22:45:50 2009
+++ src/dist/nvi/common/conv.c	Wed Jan 23 13:51:51 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: conv.c,v 1.6 2009/01/18 03:45:50 lukem Exp $ */
+/*	$NetBSD: conv.c,v 1.7 2013/01/23 18:51:51 christos Exp $ */
 
 /*-
  * Copyright (c) 1993, 1994
@@ -62,6 +62,21 @@ raw2int(SCR *sp, const char * str, ssize
 return 0;
 }
 
+#ifndef ERROR_ON_CONVERT
+#define HANDLE_ICONV_ERROR(o, i, ol, il) do {\
+		*o++ = *i++;		\
+		ol--; il--;		\
+	} while (/*CONSTCOND*/0)
+#define HANDLE_MBR_ERROR(n, mbs, d, s) do {\
+		d = s;			\
+		MEMSET(&mbs, 0, 1); 	\
+		n = 1; 			\
+	} while (/*CONSTCOND*/0)
+#else
+#define HANDLE_ICONV_ERROR goto err
+#define	HANDLE_MBR_ERROR goto err
+#endif
+
 #define CONV_BUFFER_SIZE512
 /* fill the buffer with codeset encoding of string pointed to by str
  * left has the number of bytes left in str and is adjusted
@@ -74,9 +89,9 @@ raw2int(SCR *sp, const char * str, ssize
 	char *bp = buffer;		\
 	outleft = CONV_BUFFER_SIZE;	\
 	errno = 0;			\
-	if (iconv(id, (const char **)&str, &left, &bp, &outleft) == (size_t)-1 \
-		/* && errno != E2BIG */)\
-	goto err;			\
+	if (iconv(id, (const char **)&str, &left, &bp, &outleft) 	\
+	== (size_t)-1 /* && errno != E2BIG */)			\
+		HANDLE_ICONV_ERROR(bp, str, outleft, left);		\
 	if ((len = CONV_BUFFER_SIZE - outleft) == 0) {			\
 	error = -left;		\
 	goto err;			\
@@ -120,7 +135,8 @@ default_char2int(SCR *sp, const char * s
 	n = mbrtowc((*tostr)+i, src+j, len-j, &mbs);
 	/* NULL character converted */
 	if (n == (size_t)-2) error = -(len-j);
-	if (n == (size_t)-1 || n == (size_t)-2) goto err;
+	if (n == (size_t)-1 || n == (size_t)-2)
+	HANDLE_MBR_ERROR(n, mbs, (*tostr)[i], src[j]); 
 	if (n == 0) n = 1;
 	j += n;
 	if (++i >= *blen) {
@@ -243,8 +259,8 @@ default_int2char(SCR *sp, const CHAR_T *
 	}				\
 	errno = 0;			\
 	if (iconv(id, &bp, &len, &obp, &outleft) == (size_t)-1 &&	\
-		errno != E2BIG)	\
-		goto err;		\
+		errno != E2BIG) 	\
+		HANDLE_ICONV_ERROR(obp, bp, outleft, len);		\
 	offset = cw->blen1 - outleft;			\
 	}			\
 } while (0)
@@ -268,7 +284,8 @@ default_int2char(SCR *sp, const CHAR_T *
 
 for (i = 0, j = 0; i < (size_t)len; ++i) {
 	n = wcrtomb(dst+j, str[i], &mbs);
-	if (n == (size_t)-1) goto err;
+	if (n == (size_t)-1) 
+	   HANDLE_MBR_ERROR(n, mbs, dst[j], str[i]);
 	j += n;
 	if (buflen < j + MB_CUR_MAX) {
 	if (id != (iconv_t)-1) {



CVS commit: src/dist/nvi/common

2012-07-15 Thread S.P.Zeidler
Module Name:src
Committed By:   spz
Date:   Sun Jul 15 09:13:59 UTC 2012

Modified Files:
src/dist/nvi/common: exf.c

Log Message:
Use after free (Coverity 273146)


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/dist/nvi/common/exf.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/dist/nvi/common/exf.c
diff -u src/dist/nvi/common/exf.c:1.4 src/dist/nvi/common/exf.c:1.5
--- src/dist/nvi/common/exf.c:1.4	Sat Nov 14 20:01:20 2009
+++ src/dist/nvi/common/exf.c	Sun Jul 15 09:13:59 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: exf.c,v 1.4 2009/11/14 20:01:20 tnozaki Exp $ */
+/*	$NetBSD: exf.c,v 1.5 2012/07/15 09:13:59 spz Exp $ */
 
 /*-
  * Copyright (c) 1992, 1993, 1994
@@ -173,6 +173,7 @@ file_init(SCR *sp, FREF *frp, char *rcv_
 			exfp->minode == sb.st_ino && 
 			(exfp != sp->ep || exfp->refcnt > 1)) {
 ep = exfp;
+oname = ep->rcv_path;
 goto postinit;
 			}
 		}
@@ -807,8 +808,10 @@ file_end(SCR *sp, EXF *ep, int force)
 		(void)close(ep->rcv_fd);
 	if (ep->env_path != NULL)
 		free(ep->env_path);
-	if (ep->rcv_path != NULL)
+	if (ep->rcv_path != NULL) {
 		free(ep->rcv_path);
+		ep->rcv_path = NULL;
+	}
 	if (ep->rcv_mpath != NULL)
 		free(ep->rcv_mpath);
 
@@ -1251,6 +1254,8 @@ file_backup(SCR *sp, const char *name, c
 	}
 	if (bp != NULL)
 		FREE_SPACE(sp, bp, blen);
+	if (d != NULL)
+		free(d);
 	return (0);
 
 alloc_err:



CVS commit: src/dist/nvi/common

2012-01-21 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Jan 21 19:56:46 UTC 2012

Modified Files:
src/dist/nvi/common: cut.c

Log Message:
remove error(1) line.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/dist/nvi/common/cut.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/dist/nvi/common/cut.c
diff -u src/dist/nvi/common/cut.c:1.7 src/dist/nvi/common/cut.c:1.8
--- src/dist/nvi/common/cut.c:1.7	Sat Jan 21 14:49:56 2012
+++ src/dist/nvi/common/cut.c	Sat Jan 21 14:56:46 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: cut.c,v 1.7 2012/01/21 19:49:56 christos Exp $ */
+/*	$NetBSD: cut.c,v 1.8 2012/01/21 19:56:46 christos Exp $ */
 
 /*-
  * Copyright (c) 1992, 1993, 1994
@@ -257,7 +257,6 @@ cut_line(SCR *sp, db_recno_t lno, size_t
 	 * copy the portion we want, and reset the TEXT length.
 	 */
 	if (len != 0) {
-/*###260 [cc] error: comparison between signed and unsigned integer expressions%%%*/
 		if (clen == ENTIRE_LINE)
 			clen = len - fcno;
 		MEMCPYW(tp->lb, p + fcno, clen);



CVS commit: src/dist/nvi/common

2012-01-21 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Jan 21 19:49:56 UTC 2012

Modified Files:
src/dist/nvi/common: cut.c delete.c

Log Message:
make the previous patch compile.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/dist/nvi/common/cut.c
cvs rdiff -u -r1.4 -r1.5 src/dist/nvi/common/delete.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/dist/nvi/common/cut.c
diff -u src/dist/nvi/common/cut.c:1.6 src/dist/nvi/common/cut.c:1.7
--- src/dist/nvi/common/cut.c:1.6	Sat Jan 21 14:32:37 2012
+++ src/dist/nvi/common/cut.c	Sat Jan 21 14:49:56 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: cut.c,v 1.6 2012/01/21 19:32:37 christos Exp $ */
+/*	$NetBSD: cut.c,v 1.7 2012/01/21 19:49:56 christos Exp $ */
 
 /*-
  * Copyright (c) 1992, 1993, 1994
@@ -134,7 +134,7 @@ copyloop:
 	}
 
 
-#define	ENTIRE_LINE	-1
+#define	ENTIRE_LINE	(size_t)-1
 	/* In line mode, it's pretty easy, just cut the lines. */
 	if (LF_ISSET(CUT_LINEMODE)) {
 		cbp->flags |= CB_LMODE;
@@ -257,6 +257,7 @@ cut_line(SCR *sp, db_recno_t lno, size_t
 	 * copy the portion we want, and reset the TEXT length.
 	 */
 	if (len != 0) {
+/*###260 [cc] error: comparison between signed and unsigned integer expressions%%%*/
 		if (clen == ENTIRE_LINE)
 			clen = len - fcno;
 		MEMCPYW(tp->lb, p + fcno, clen);

Index: src/dist/nvi/common/delete.c
diff -u src/dist/nvi/common/delete.c:1.4 src/dist/nvi/common/delete.c:1.5
--- src/dist/nvi/common/delete.c:1.4	Sat Jan 21 14:35:02 2012
+++ src/dist/nvi/common/delete.c	Sat Jan 21 14:49:56 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: delete.c,v 1.4 2012/01/21 19:35:02 christos Exp $ */
+/*	$NetBSD: delete.c,v 1.5 2012/01/21 19:49:56 christos Exp $ */
 
 /*-
  * Copyright (c) 1992, 1993, 1994
@@ -65,7 +65,7 @@ del(SCR *sp, MARK *fm, MARK *tm, int lmo
 		if (tm->lno == lno) {
 			if (db_get(sp, lno, DBG_FATAL, &p, &len))
 return (1);
-			eof = tm->cno != -1 && tm->cno >= len ? 1 : 0;
+			eof = tm->cno != (size_t)-1 && tm->cno >= len ? 1 : 0;
 		} else
 			eof = 1;
 		if (eof) {



CVS commit: src/dist/nvi/common

2012-01-21 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Jan 21 19:35:02 UTC 2012

Modified Files:
src/dist/nvi/common: delete.c

Log Message:
PR/10367: Second part.
Restore lost fix:
http://mail-index.netbsd.org/source-changes/2001/09/09/0043.html

Fix a test condition for EOF.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/dist/nvi/common/delete.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/dist/nvi/common/delete.c
diff -u src/dist/nvi/common/delete.c:1.3 src/dist/nvi/common/delete.c:1.4
--- src/dist/nvi/common/delete.c:1.3	Sat Jan 21 14:29:41 2012
+++ src/dist/nvi/common/delete.c	Sat Jan 21 14:35:02 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: delete.c,v 1.3 2012/01/21 19:29:41 christos Exp $ */
+/*	$NetBSD: delete.c,v 1.4 2012/01/21 19:35:02 christos Exp $ */
 
 /*-
  * Copyright (c) 1992, 1993, 1994
@@ -65,7 +65,7 @@ del(SCR *sp, MARK *fm, MARK *tm, int lmo
 		if (tm->lno == lno) {
 			if (db_get(sp, lno, DBG_FATAL, &p, &len))
 return (1);
-			eof = tm->cno >= len ? 1 : 0;
+			eof = tm->cno != -1 && tm->cno >= len ? 1 : 0;
 		} else
 			eof = 1;
 		if (eof) {



CVS commit: src/dist/nvi/common

2012-01-21 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Jan 21 19:32:37 UTC 2012

Modified Files:
src/dist/nvi/common: cut.c

Log Message:
PR/10367:

Restore lost fix:
http://mail-index.netbsd.org/source-changes/2001/09/09/0042.html

Define ENTIRE_LINE to be -1 instead of 0 since we may want to copy 0 characters.
(and use ENTIRE_LINE instead of 0 where appropriate)

This fixes a bug in the dw command with for example:


a b c

~
~
if you hit dw there, only the empty line would be killed but both the empty
line and the subsequent one would be pasted when asked for with P for example.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/dist/nvi/common/cut.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/dist/nvi/common/cut.c
diff -u src/dist/nvi/common/cut.c:1.5 src/dist/nvi/common/cut.c:1.6
--- src/dist/nvi/common/cut.c:1.5	Wed Nov 23 14:25:28 2011
+++ src/dist/nvi/common/cut.c	Sat Jan 21 14:32:37 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: cut.c,v 1.5 2011/11/23 19:25:28 tnozaki Exp $ */
+/*	$NetBSD: cut.c,v 1.6 2012/01/21 19:32:37 christos Exp $ */
 
 /*-
  * Copyright (c) 1992, 1993, 1994
@@ -134,16 +134,16 @@ copyloop:
 	}
 
 
-#define	ENTIRE_LINE	0
+#define	ENTIRE_LINE	-1
 	/* In line mode, it's pretty easy, just cut the lines. */
 	if (LF_ISSET(CUT_LINEMODE)) {
 		cbp->flags |= CB_LMODE;
 		for (lno = fm->lno; lno <= tm->lno; ++lno)
-			if (cut_line(sp, lno, 0, 0, cbp))
+			if (cut_line(sp, lno, 0, ENTIRE_LINE, cbp))
 goto cut_line_err;
 	} else {
 		/*
-		 * Get the first line.  A length of 0 causes cut_line
+		 * Get the first line.  A length of ENTIRE_LINE causes cut_line
 		 * to cut from the MARK to the end of the line.
 		 */
 		if (cut_line(sp, fm->lno, fm->cno, fm->lno != tm->lno ?
@@ -257,7 +257,7 @@ cut_line(SCR *sp, db_recno_t lno, size_t
 	 * copy the portion we want, and reset the TEXT length.
 	 */
 	if (len != 0) {
-		if (clen == 0)
+		if (clen == ENTIRE_LINE)
 			clen = len - fcno;
 		MEMCPYW(tp->lb, p + fcno, clen);
 		tp->len = clen;



CVS commit: src/dist/nvi/common

2011-11-14 Thread Takehiko NOZAKI
Module Name:src
Committed By:   tnozaki
Date:   Mon Nov 14 13:29:07 UTC 2011

Modified Files:
src/dist/nvi/common: key.h

Log Message:
nvi cannot display international character(west european accented chars).
reported by Ian D. Leroux at current-users, thanks a lot!


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/dist/nvi/common/key.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/dist/nvi/common/key.h
diff -u src/dist/nvi/common/key.h:1.2 src/dist/nvi/common/key.h:1.3
--- src/dist/nvi/common/key.h:1.2	Mon Mar 21 14:53:02 2011
+++ src/dist/nvi/common/key.h	Mon Nov 14 13:29:07 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: key.h,v 1.2 2011/03/21 14:53:02 tnozaki Exp $ */
+/*	$NetBSD: key.h,v 1.3 2011/11/14 13:29:07 tnozaki Exp $ */
 
 /*-
  * Copyright (c) 1991, 1993, 1994
@@ -28,7 +28,7 @@
 sp->conv.input2int(sp, n, nlen, &(cw), &wlen, &w)
 #define CONST
 #define CHAR_WIDTH(sp, ch)  wcwidth(ch)
-#define INTISWIDE(c)	(!!(c >> 8))	/* XXX wrong name */
+#define INTISWIDE(c)	(wctob(c) == EOF)	/* XXX wrong name */
 #else
 #define FILE2INT5(sp,buf,n,nlen,w,wlen) \
 (w = n, wlen = nlen, 0)



CVS commit: src/dist/nvi/common

2010-11-14 Thread Eric Schnoebelen
Module Name:src
Committed By:   schnoebe
Date:   Sun Nov 14 20:53:54 UTC 2010

Modified Files:
src/dist/nvi/common: options.c

Log Message:
bin/44088

Change the initialization state of gtagsmode to 0, (unset).

This brings about least astonishment for users, permittings tags
functionality to work as expected.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/dist/nvi/common/options.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/dist/nvi/common/options.c
diff -u src/dist/nvi/common/options.c:1.8 src/dist/nvi/common/options.c:1.9
--- src/dist/nvi/common/options.c:1.8	Thu May 13 17:52:11 2010
+++ src/dist/nvi/common/options.c	Sun Nov 14 20:53:54 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: options.c,v 1.8 2010/05/13 17:52:11 tnozaki Exp $ */
+/*	$NetBSD: options.c,v 1.9 2010/11/14 20:53:54 schnoebe Exp $ */
 
 /*-
  * Copyright (c) 1991, 1993, 1994
@@ -98,7 +98,7 @@
 	{L("flash"),	NULL,		OPT_1BOOL,	0},
 #ifdef GTAGS
 /* O_GTAGSMODE	FreeBSD/NetBSD */
-	{L("gtagsmode"),NULL,		OPT_1BOOL,	0},
+	{L("gtagsmode"),NULL,		OPT_0BOOL,	0},
 #endif
 /* O_HARDTABS	4BSD */
 	{L("hardtabs"),	NULL,		OPT_NUM,	0},



CVS commit: src/dist/nvi/common

2009-11-14 Thread Takehiko NOZAKI
Module Name:src
Committed By:   tnozaki
Date:   Sat Nov 14 20:01:20 UTC 2009

Modified Files:
src/dist/nvi/common: exf.c

Log Message:
fix format string bug, filename may contain % character, don't use it as format 
string.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/dist/nvi/common/exf.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/dist/nvi/common/exf.c
diff -u src/dist/nvi/common/exf.c:1.3 src/dist/nvi/common/exf.c:1.4
--- src/dist/nvi/common/exf.c:1.3	Tue Dec  9 18:26:20 2008
+++ src/dist/nvi/common/exf.c	Sat Nov 14 20:01:20 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: exf.c,v 1.3 2008/12/09 18:26:20 christos Exp $ */
+/*	$NetBSD: exf.c,v 1.4 2009/11/14 20:01:20 tnozaki Exp $ */
 
 /*-
  * Copyright (c) 1992, 1993, 1994
@@ -945,7 +945,7 @@
 	 * Note that this code is harmless if you're using libc 4.6.x.
 	 */
 	if (LF_ISSET(FS_APPEND) && lseek(fd, (off_t)0, SEEK_END) < 0) {
-		msgq(sp, M_SYSERR, name);
+		msgq(sp, M_SYSERR, "%s", name);
 		return (1);
 	}
 #endif
@@ -1064,7 +1064,7 @@
 			*--s = '.';
 		}
 	}
-	msgq(sp, M_INFO, s);
+	msgq(sp, M_INFO, "%s", s);
 	if (nf)
 		FREE_SPACE(sp, p, 0);
 	return (0);