diff --git a/buffer.c b/buffer.c index d85466d..1aa0340 100644 --- a/buffer.c +++ b/buffer.c @@ -56,9 +56,8 @@ buffer_t *buffer_new(void) { // Wrapper for buffer_new + buffer_open buffer_t *buffer_new_open(char *path) { buffer_t *self; - int rc; self = buffer_new(); - if ((rc = buffer_open(self, path)) != MLBUF_OK) { + if (buffer_open(self, path) != MLBUF_OK) { buffer_destroy(self); return NULL; } @@ -702,7 +701,8 @@ int buffer_get_bline_w_hint(buffer_t *self, bint_t line_index, bline_t *opt_hint MLBUF_MAKE_GT_EQ0(line_index); if (!opt_hint) { - opt_hint = self->first_line; + *ret_bline = NULL; + return MLBUF_ERR; } fwd = opt_hint; @@ -1407,6 +1407,11 @@ static int _buffer_redo(buffer_t *self, int by_group) { // Get line to perform undo on bline = NULL; buffer_get_bline(self, action_to_redo->start_line_index, &bline); + + if (!bline){ + return MLBUF_ERR; + } + MLBUF_BLINE_ENSURE_CHARS(bline); if (!bline) { return MLBUF_ERR; @@ -1481,7 +1486,6 @@ static int _buffer_apply_styles_all(bline_t *bline, bint_t min_nlines) { open_rule = bline->prev ? bline->prev->eol_rule : NULL; styled_nlines = 0; col = 0; - eol_rule_changed = 0; _buffer_bline_reset_styles(bline); diff --git a/cmd.c b/cmd.c index 6382778..1076421 100644 --- a/cmd.c +++ b/cmd.c @@ -520,8 +520,8 @@ int cmd_replace_all(cmd_context_t *ctx) { cancelled = 0; regex = NULL; replacement = NULL; - num_bviews = 0; CDL_COUNT2(ctx->editor->all_bviews, bview, num_bviews, all_next); + if (num_bviews <= 0) return MLBUF_ERR; buffer_done = calloc(num_bviews, sizeof(buffer_t *)); buffer_done_i = 0; @@ -1619,7 +1619,6 @@ static int _cmd_save(editor_t *editor, bview_t *bview, int save_as) { struct stat st; bint_t nbytes; - fname_changed = 0; do { if (!bview->buffer->path || save_as) { // Prompt for name @@ -1900,8 +1899,8 @@ static int _cmd_menu_ctag_cb(cmd_context_t *ctx) { } re += 2; // Skip leading `/^` re_len -= 2; - re[re_len-4] = '\0'; // Trunc trailing `$/;"` re_len -= 4; + re[re_len] = '\0'; // Trunc trailing `$/;"` util_pcre_replace("([\\.\\\\\\+\\*\\?\\^\\$\\[\\]\\(\\)\\{\\}\\=\\!\\>\\<\\|\\:\\-])", re, "\\\\$1", &qre, &qre_len); editor_close_bview(ctx->editor, ctx->bview, NULL); editor_open_bview(ctx->editor, NULL, MLE_BVIEW_TYPE_EDIT, fname, strlen(fname), 1, 0, 0, NULL, &bview); diff --git a/editor.c b/editor.c index 50670b1..c6b15d0 100644 --- a/editor.c +++ b/editor.c @@ -647,7 +647,9 @@ static int _editor_close_bview_inner(editor_t *editor, bview_t *bview, int *optr if (!bview->split_parent) { DL_DELETE2(editor->top_bviews, bview, top_prev, top_next); } - CDL_DELETE2(editor->all_bviews, bview, all_prev, all_next); + if (bview->all_next && bview->all_prev) { + CDL_DELETE2(editor->all_bviews, bview, all_prev, all_next); + } bview_destroy(bview); if (optret_num_closed) *optret_num_closed += 1; return MLE_OK; @@ -1514,8 +1516,14 @@ static kbinding_t *_editor_get_kbinding_node(kbinding_t *node, kinput_t *input, } } + // Look for input + if (!node){ + return NULL; + } + HASH_FIND(hh, node->children, input, sizeof(kinput_t), binding); + if (binding) { return binding; } @@ -2268,7 +2276,13 @@ static void _editor_init_syntax_add_rule(syntax_t *syntax, srule_def_t *def) { } else { node->srule = srule_new_single(def->re, strlen(def->re), 0, def->fg, def->bg); } - if (node->srule) DL_APPEND(syntax->srules, node); + + if (node->srule){ + DL_APPEND(syntax->srules, node); + return; + } + + free(node); } // Proxy for _editor_init_syntax_add_rule with str in format ',,,' or ',,' diff --git a/util.c b/util.c index 6573b64..36b9e3d 100644 --- a/util.c +++ b/util.c @@ -275,7 +275,6 @@ int util_pcre_replace(char *re, char *subj, char *repl, char **ret_result, int * num_repls = 0; subj_len = strlen(subj); subj_offset = 0; - subj_offset_z = 0; subj_look_offset = 0; last_look_offset = 0; while (subj_offset < subj_len) { @@ -533,9 +532,9 @@ void str_sprintf(str_t *str, const char *fmt, ...) { void str_put_len(str_t *str, char *data, size_t data_len, int is_prepend) { size_t req_cap; req_cap = str->len + data_len + 1; - if (req_cap > str->cap) { - str_ensure_cap(str, req_cap); - } + + str_ensure_cap(str, req_cap); + if (is_prepend) { memmove(str->data + data_len, str->data, str->len); memcpy(str->data, data, data_len); @@ -548,7 +547,7 @@ void str_put_len(str_t *str, char *data, size_t data_len, int is_prepend) { // Ensure space in str void str_ensure_cap(str_t *str, size_t cap) { - if (cap > str->cap) { + if (!str->data || cap > str->cap) { if (str->inc >= 0) { // If inc is positive, grow linearly cap = MLBUF_MAX(cap, str->cap + (str->inc > 0 ? str->inc : 128));