vile
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [vile] writing an empty file with nonewline


From: Thomas Dickey
Subject: Re: [vile] writing an empty file with nonewline
Date: Mon, 22 May 2006 21:09:25 -0400 (EDT)

On Mon, 22 May 2006, Brendan O'Dea wrote:

There seems to be a problem when writing out an empty file when
nonewline is set (see http://bugs.debian.org/368007).
...
Not sure exactly where the root of the problem lies; setup_file_region()
seems to copy that -1 value from bp->b_bytecount, which should similarly
be unsigned.

The problem is in bsizes(), has been there since I changed B_COUNT to an unsigned a year ago (21 May 2005). Here's a paste from the fix I just
checked in:

diff -u -r1.299 buffer.c
--- buffer.c    2006/04/25 20:14:32     1.299
+++ buffer.c    2006/05/23 00:58:39
@@ -5,7 +5,7 @@
  * keys. Like everyone else, they set hints
  * for the display system.
  *
- * $Header: /usr/build/vile/vile/RCS/buffer.c,v 1.299 2006/04/25 20:14:32 tom 
Exp $
+ * $Header: /usr/build/vile/vile/RCS/buffer.c,v 1.300 2006/05/23 00:58:39 tom 
Exp $
  *
  */

@@ -2511,9 +2511,9 @@
     if (valid_buffer(curbp)
        && !b_is_counted(bp)) {
        LINE *lp;               /* current line */
+       B_COUNT ending = len_record_sep(bp);
        B_COUNT numchars = 0;   /* # of chars in file */
        L_NUM numlines = 0;     /* # of lines in file */
-       L_NUM ending = len_record_sep(bp);

        /* count chars and lines */
        for_each_line(lp, bp) {
@@ -2523,8 +2523,12 @@
            lp->l_number = numlines;
 #endif
        }
-       if (!b_val(bp, MDNEWLINE))
-           numchars -= ending;
+       if (!b_val(bp, MDNEWLINE)) {
+           if (numchars > ending)
+               numchars -= ending;
+           else
+               numchars = 0;
+       }

        bp->b_bytecount = numchars;
        bp->b_linecount = numlines;

--
Thomas E. Dickey
http://invisible-island.net
ftp://invisible-island.net




reply via email to

[Prev in Thread] Current Thread [Next in Thread]