vis

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

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

commit 1cdb1e9fb84f293626b8c6a19aa26897f5e46f08
parent cf7aba3a92e2423c8051e1c34875644509d7382f
Author: Marc André Tanner <mat@brain-dump.org>
Date:   Thu, 22 Dec 2016 12:32:33 +0100

text: change datatype of Mark to uintptr_t

This should avoid undefined pointer comparisons.

Diffstat:
Mtext.c | 10++++++----
Mtext.h | 3++-
Mvis-lua.c | 2+-
Mvis-motions.c | 4++--
Mvis.c | 2+-
5 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/text.c b/text.c @@ -1634,8 +1634,8 @@ Mark text_mark_set(Text *txt, size_t pos) { return (Mark)&txt->end; Location loc = piece_get_extern(txt, pos); if (!loc.piece) - return NULL; - return loc.piece->data + loc.off; + return (Mark)NULL; + return (Mark)(loc.piece->data + loc.off); } size_t text_mark_get(Text *txt, Mark mark) { @@ -1649,8 +1649,10 @@ size_t text_mark_get(Text *txt, Mark mark) { return txt->size; for (Piece *p = txt->begin.next; p->next; p = p->next) { - if (p->data <= mark && mark < p->data + p->len) - return cur + (mark - p->data); + Mark start = (Mark)(p->data); + Mark end = start + p->len; + if (start <= mark && mark < end) + return cur + (mark - start); cur += p->len; } diff --git a/text.h b/text.h @@ -2,6 +2,7 @@ #define TEXT_H #include <stdbool.h> +#include <stdint.h> #include <time.h> #include <unistd.h> #include <stdarg.h> @@ -99,7 +100,7 @@ bool text_iterator_codepoint_prev(Iterator *it, char *c); bool text_iterator_char_next(Iterator*, char *c); bool text_iterator_char_prev(Iterator*, char *c); -typedef const char* Mark; +typedef uintptr_t Mark; /* mark position `pos', the returned mark can be used to later retrieve * the same text segment */ Mark text_mark_set(Text*, size_t pos); diff --git a/vis-lua.c b/vis-lua.c @@ -1609,7 +1609,7 @@ static int file_mark_set(lua_State *L) { */ static int file_mark_get(lua_State *L) { File *file = obj_ref_check(L, 1, "vis.file"); - Mark mark = obj_lightref_check(L, 2, "vis.file.mark"); + Mark mark = (Mark)obj_lightref_check(L, 2, "vis.file.mark"); size_t pos = text_mark_get(file->text, mark); if (pos == EPOS) lua_pushnil(L); diff --git a/vis-motions.c b/vis-motions.c @@ -165,7 +165,7 @@ static size_t window_changelist_prev(Vis *vis, Win *win, size_t pos) { static size_t window_jumplist_next(Vis *vis, Win *win, size_t cur) { while (win->jumplist) { - Mark mark = ringbuf_next(win->jumplist); + Mark mark = (Mark)ringbuf_next(win->jumplist); if (!mark) return cur; size_t pos = text_mark_get(win->file->text, mark); @@ -177,7 +177,7 @@ static size_t window_jumplist_next(Vis *vis, Win *win, size_t cur) { static size_t window_jumplist_prev(Vis *vis, Win *win, size_t cur) { while (win->jumplist) { - Mark mark = ringbuf_prev(win->jumplist); + Mark mark = (Mark)ringbuf_prev(win->jumplist); if (!mark) return cur; size_t pos = text_mark_get(win->file->text, mark); diff --git a/vis.c b/vis.c @@ -626,7 +626,7 @@ void vis_keymap_disable(Vis *vis) { static void window_jumplist_add(Win *win, size_t pos) { Mark mark = text_mark_set(win->file->text, pos); if (mark && win->jumplist) - ringbuf_add(win->jumplist, mark); + ringbuf_add(win->jumplist, (void*)mark); } static void window_jumplist_invalidate(Win *win) {