vis

a vi-like editor based on Plan 9's structural regular expressions

git clone https://9o.is/git/vis.git

commit 72eaf7c03ced75c71de5d381662fc377b80ff46b
parent a005842c9da011a67bed4ed75aafc2fbff13cb24
Author: Marc André Tanner <mat@brain-dump.org>
Date:   Sun, 28 Jun 2015 22:22:42 +0200

Do not take address of variables which go out of scope

This is a bit of a hack, since now the callers range
is modified. The various cmd_* functions should probably
take a const Filerange pointer as argument and modify
a local Filerange variable if needed.

Diffstat:
Mvis.c | 8++++----
1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/vis.c b/vis.c @@ -1573,7 +1573,7 @@ static bool cmd_read(Filerange *range, enum CmdOpt opt, const char *argv[]) { size_t pos = view_cursor_get(vis->win->view); if (!text_range_valid(range)) - range = &(Filerange){ .start = pos, .end = pos }; + *range = (Filerange){ .start = pos, .end = pos }; Filerange delete = *range; range->start = range->end; @@ -1586,7 +1586,7 @@ static bool cmd_read(Filerange *range, enum CmdOpt opt, const char *argv[]) { static bool cmd_substitute(Filerange *range, enum CmdOpt opt, const char *argv[]) { char pattern[255]; if (!text_range_valid(range)) - range = &(Filerange){ .start = 0, .end = text_size(vis->win->file->text) }; + *range = (Filerange){ .start = 0, .end = text_size(vis->win->file->text) }; snprintf(pattern, sizeof pattern, "s%s", argv[1]); return cmd_filter(range, opt, (const char*[]){ argv[0], "sed", pattern, NULL}); } @@ -1636,7 +1636,7 @@ static bool cmd_wq(Filerange *range, enum CmdOpt opt, const char *argv[]) { static bool cmd_write(Filerange *range, enum CmdOpt opt, const char *argv[]) { Text *text = vis->win->file->text; if (!text_range_valid(range)) - range = &(Filerange){ .start = 0, .end = text_size(text) }; + *range = (Filerange){ .start = 0, .end = text_size(text) }; if (!argv[1]) argv[1] = text_filename_get(text); if (!argv[1]) { @@ -1744,7 +1744,7 @@ static bool cmd_filter(Filerange *range, enum CmdOpt opt, const char *argv[]) { fcntl(perr[0], F_SETFL, O_NONBLOCK); if (interactive) - range = &(Filerange){ .start = pos, .end = pos }; + *range = (Filerange){ .start = pos, .end = pos }; /* ranges which are written to the filter and read back in */ Filerange rout = *range;