vis
a vi-like editor based on Plan 9's structural regular expressions
git clone https://9o.is/git/vis.git
commit cf5f89a59312ec8de50396572dc1a2091cc883fe parent 615c94fdd164b440a33770e9d793bc00f8f8abba Author: Marc André Tanner <mat@brain-dump.org> Date: Wed, 3 May 2017 10:54:02 +0200 text: rename text_sigbus to text_mmaped Add casts to uintptr_t to avoid unrelated pointer comparisons. Diffstat:
| M | text.c | | | 5 | +++-- |
| M | text.h | | | 8 | +++++--- |
| M | vis.c | | | 2 | +- |
3 files changed, 9 insertions(+), 6 deletions(-)
diff --git a/text.c b/text.c @@ -1312,10 +1312,11 @@ bool text_modified(Text *txt) { return txt->saved_revision != txt->history; } -bool text_sigbus(Text *txt, const char *addr) { +bool text_mmaped(Text *txt, const char *ptr) { + uintptr_t addr = (uintptr_t)ptr; for (Block *blk = txt->blocks; blk; blk = blk->next) { if ((blk->type == MMAP_ORIG || blk->type == MMAP) && - blk->data <= addr && addr < blk->data + blk->size) + (uintptr_t)(blk->data) <= addr && addr < (uintptr_t)(blk->data + blk->size)) return true; } return false; diff --git a/text.h b/text.h @@ -254,9 +254,11 @@ Mark text_mark_set(Text*, size_t pos); size_t text_mark_get(Text*, Mark); /** @} */ -/* query whether `addr` is part of a memory mapped region associated with - * this text instance */ -bool text_sigbus(Text*, const char *addr); +/** + * Check whether ``ptr`` is part of a memory mapped region associated with + * this text instance. + */ +bool text_mmaped(Text*, const char *ptr); /** * @defgroup save diff --git a/vis.c b/vis.c @@ -1274,7 +1274,7 @@ bool vis_signal_handler(Vis *vis, int signum, const siginfo_t *siginfo, const vo switch (signum) { case SIGBUS: for (File *file = vis->files; file; file = file->next) { - if (text_sigbus(file->text, siginfo->si_addr)) + if (text_mmaped(file->text, siginfo->si_addr)) file->truncated = true; } vis->sigbus = true;