Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clang's scan-base warning fixes #85

Closed
wants to merge 12 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down
5 changes: 2 additions & 3 deletions cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
18 changes: 16 additions & 2 deletions editor.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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 '<start>,<end>,<fg>,<bg>' or '<regex>,<fg>,<bg>'
Expand Down
9 changes: 4 additions & 5 deletions util.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand All @@ -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));
Expand Down