This expression was wrong, but it was causing a false positive
in some compilers that couldn't see that error() cannot return.
The actual problem of the line is that it was too complex and it is better
to split it in simplex expressions.
Copy was using directly the line numbers and incrementing them
without calling nextln(). It also didn't worry about how
line numbers are modified when we insert new lines.
Current handling of strings is a bit messy. This type is copied
from the sed implementation. Addchar_ is added to be able to live
with String and old style chars based in 3 different variables.
From 6665eaa1d2c25a95b44a4f4fb3d24a3bd5c1180f Mon Sep 17 00:00:00 2001
From: Thomas Mannay <audiobarrier@openmailbox.org>
Date: Thu, 3 Nov 2016 15:16:32 +0000
Subject: [PATCH] Treat addresses of 0 as 1 for insert
By stripping backslashes this code caused a number of bugs.
'\<digit>' expressions caused literal <digit>s to be subbed-in,
'\&' was treated identically to '&', and other escaped characters
added garbage to the string.
regexec(3) happily matches /^$/ against the text of line
zero (the null string), causing an error.
Also update email address for Wolfgang Corcoran-Mathe
Given:
static int marks['z' - 'a'];
marks[c];
In this case c is the character read and index is out of bounds. We
need marks[c - 'a']
While playing around with optimization settings gcc caught caught this.
Also fix one check for c, change from isalpha to islower.
-emg
From 2cc36818283e9068576c1042690c016a81b709a3 Mon Sep 17 00:00:00 2001
From: Evan Gates <evan.gates@gmail.com>
Date: Fri, 15 Jul 2016 09:52:39 -0700
Subject: [PATCH] fix marks indexing
It is impossible to rematch a pattern which has one (or both)
of these operators, so the simplest solucion is detect them
while we are compiling the regular expression and break the
match loop after the first iteration.
Ed was falling doing substitution different of the first or all
(s//%/, s//%/\1, s//%/g), because it was not adding the matches
which were not going to be substituted.
Rematch() was incremnenting the last match always, even in the
cases when it was not matching anything. This patch detects
this situation and it updates it only when there is a match.
Line 0 is a special line added to allow operations with
empty buffers, and we have to ensure that it is not going
to match any regular expression. The code was written in
a way that this case was handle implicitily, but this
solution was working only for the first file loaded in
ed, while the second file loaded in ed got a line with
a dirty seek field. This solution check explicitily
against invalid lines passed to makeline(), which
allows to simplify the common case.
The current behaviour of storing the scratch file in
the current directory is a bit painful, because it
generates files in all the directories where you
execute ed. BSD ed uses TMPDIR for this purpouse,
so if the user wants to put the scratch file in
other place different of /tmp it only has to set
this variable.
This patch introduced init() function, which removed the initialization
code of savfname in doread, but this is incorrect, because savfname
can be initialized with a r command if savfname is empty.
These funcction initializes the scratch buffer, and in case of
having a file name parameter it loads the file in the scratch.
It also fixes a problem before this version, where the saved
filename was not set when the file didn't exist.
For the same reason we don't care about the state of
the buffer in clearundo() we can reset modflag in
clearbuf(), because after calling it we don't want
to know anything about the previous state.
When we discard the content of an undo buffer
is because we don't need it anymore, and it means
that we don't care about the modify state of the buffer
so we can reset the modflag in clearundo(), and
remove this assignation each time clearundo() is called.