tFix minor issues - ledit - Text editor (WIP) | |
git clone git://lumidify.org/ledit.git (fast, but not encrypted) | |
git clone https://lumidify.org/git/ledit.git (encrypted, but very slow) | |
Log | |
Files | |
Refs | |
README | |
LICENSE | |
--- | |
commit 320bd075762fe538d0e997bc2573bea19385c3a8 | |
parent fbec4c07cb92b740d88ac37f69754f796fa1ebb9 | |
Author: lumidify <[email protected]> | |
Date: Sun, 16 Jan 2022 13:25:28 +0100 | |
Fix minor issues | |
Diffstat: | |
M LICENSE | 2 +- | |
M buffer.c | 9 ++++++++- | |
M keys_basic.c | 7 +++++-- | |
M theme_config.h | 2 +- | |
M txtbuf.c | 2 ++ | |
M view.c | 9 +++++---- | |
M view.h | 2 ++ | |
7 files changed, 24 insertions(+), 9 deletions(-) | |
--- | |
diff --git a/LICENSE b/LICENSE | |
t@@ -3,7 +3,7 @@ Note 2: Some stuff is stolen from OpenBSD (https://openbsd.org) | |
ISC License | |
-Copyright (c) 2021 lumidify <[email protected]> | |
+Copyright (c) 2022 lumidify <[email protected]> | |
Permission to use, copy, modify, and/or distribute this software for any | |
purpose with or without fee is hereby granted, provided that the above | |
diff --git a/buffer.c b/buffer.c | |
t@@ -311,7 +311,14 @@ buffer_remove_view(ledit_buffer *buffer, ledit_view *view… | |
buffer->views + i + 1, | |
(buffer->views_num - i - 1) * sizeof(ledit_view *) | |
); | |
- buffer->views = ledit_reallocarray(buffer->views, --buffer->vi… | |
+ --buffer->views_num; | |
+ /* FIXME: use generic "vector" library to avoid problems like … | |
+ if (buffer->views_num == 0) { | |
+ free(buffer->views); | |
+ buffer->views = NULL; | |
+ } else { | |
+ buffer->views = ledit_reallocarray(buffer->views, --bu… | |
+ } | |
} | |
} | |
diff --git a/keys_basic.c b/keys_basic.c | |
t@@ -449,6 +449,9 @@ insert_text( | |
if (set_range_end) { | |
cur_range.line2 = cur_line2; | |
cur_range.byte2 = cur_index2; | |
+ } else { | |
+ /* to make static analysis happy */ | |
+ cur_range.line2 = cur_range.byte2 = 0; | |
} | |
/* FIXME: why did I ever decide to make set_range_end | |
mean exactly the opposite for the two functions? */ | |
t@@ -1226,7 +1229,6 @@ paste_normal_backwards(ledit_view *view, char *text, siz… | |
} | |
if (paste_buffer_line_based) { | |
view_wipe_line_cursor_attrs(view, view->cur_line); | |
- ledit_line *ll = buffer_get_line(view->buffer, view->cur_line); | |
size_t brk = 0; | |
if (!view->buffer->hard_line_based) { | |
size_t tmp; | |
t@@ -1238,7 +1240,7 @@ paste_normal_backwards(ledit_view *view, char *text, siz… | |
"\n", 1, 0, 0, view->cur_line, view->cur_index, 0, 1, 1 | |
); | |
size_t text_len = paste_buffer->len; | |
- ll = buffer_get_line(view->buffer, view->cur_line); | |
+ ledit_line *ll = buffer_get_line(view->buffer, view->cur_line); | |
if (paste_buffer->text[text_len-1] == '\n') { | |
/* remove trailing newline if it exists */ | |
text_len--; | |
t@@ -2251,6 +2253,7 @@ handle_key(ledit_view *view, char *key_text, size_t len,… | |
return (struct action){ACTION_NONE, NULL}; | |
} else if (len > 0 && grab_char_cb) { | |
*found = 1; | |
+ *type = 0; | |
return grab_char_cb(view, key_text, len); | |
} | |
*found = 0; | |
diff --git a/theme_config.h b/theme_config.h | |
t@@ -19,7 +19,7 @@ static const char *SELECTION_BG = "#000000"; | |
static const char *BAR_FG = "#000000"; | |
/* background color of status bar/line editor */ | |
static const char *BAR_BG = "#CCCCCC"; | |
-/* color of text cursor in status bar/line editor */ | |
+/* color of text cursor in line editor */ | |
static const char *BAR_CURSOR = "#000000"; | |
/* FIXME: give in units other than pixels */ | |
diff --git a/txtbuf.c b/txtbuf.c | |
t@@ -4,6 +4,7 @@ | |
#include "util.h" | |
#include "memory.h" | |
#include "txtbuf.h" | |
+#include "assert.h" | |
txtbuf * | |
txtbuf_new(void) { | |
t@@ -22,6 +23,7 @@ txtbuf_resize(txtbuf *buf, size_t sz) { | |
buf->text = ledit_realloc(buf->text, cap); | |
buf->cap = cap; | |
} | |
+ ledit_assert(buf->cap >= add_sz(sz, 1)); | |
} | |
void | |
diff --git a/view.c b/view.c | |
t@@ -1335,7 +1335,6 @@ view_delete_range_base( | |
size_t l1 = line_index1, b1 = byte_index1; | |
size_t l2 = line_index2, b2 = byte_index2; | |
ledit_line *ll2 = buffer_get_line(view->buffer, l2); | |
- ledit_view_line *vl1 = view_get_line(view, l1); | |
ledit_view_line *vl2 = view_get_line(view, l2); | |
PangoLayout *layout1 = get_pango_layout(view, l1); | |
PangoLayout *layout2 = get_pango_layout(view, l2); | |
t@@ -1423,9 +1422,7 @@ view_delete_range_base( | |
new_line = l1; | |
/* important so vl1->softlines is updated */ | |
set_pango_text_and_highlight(view, l1); | |
- /* important because line pointers may only st… | |
- valid until something is deleted or inserte… | |
- vl1 = view_get_line(view, l1); | |
+ ledit_view_line *vl1 = view_get_line(view, l1); | |
/* it's technically possible that the remainin… | |
second line is so small that it doesn't gen… | |
softline, so there needs to be a special ca… | |
t@@ -1632,6 +1629,8 @@ view_xy_to_line_byte(ledit_view *view, int x, int y, int… | |
} | |
h += vline->h; | |
} | |
+ *line_ret = 0; | |
+ *byte_ret = 0; | |
} | |
static void | |
t@@ -2012,6 +2011,8 @@ paste_callback(void *data, char *text, size_t len) { | |
ledit_range cur_range; | |
cur_range.line1 = view->cur_line; | |
cur_range.byte1 = view->cur_index; | |
+ /* just to avoid false positives during static analysis */ | |
+ cur_range.line2 = cur_range.byte2 = 0; | |
buffer_insert_with_undo( | |
view->buffer, cur_range, 1, 1, view->mode, | |
view->cur_line, view->cur_index, text, len, | |
diff --git a/view.h b/view.h | |
t@@ -123,6 +123,8 @@ void view_unlock(ledit_view *view); | |
/* | |
* Get the view line at the given index. | |
+ * The returned line is only valid until the next | |
+ * action that appends or deletes line entries. | |
*/ | |
ledit_view_line *view_get_line(ledit_view *view, size_t index); | |