summaryrefslogtreecommitdiff
path: root/src/dged
diff options
context:
space:
mode:
authorAlbert Cervin <albert@acervin.com>2024-03-07 21:56:36 +0100
committerAlbert Cervin <albert@acervin.com>2024-03-07 21:56:36 +0100
commitcd87d88a930a0b58cfca38678d2e757491c17b26 (patch)
tree412352d2ae67b6e64df6320d64a3cfeda0194b88 /src/dged
parenta13750209b3836a4a6a16a7ba881625f397f160f (diff)
downloaddged-cd87d88a930a0b58cfca38678d2e757491c17b26.tar.gz
dged-cd87d88a930a0b58cfca38678d2e757491c17b26.tar.xz
dged-cd87d88a930a0b58cfca38678d2e757491c17b26.zip
Fix asan errors
It found some really nasty ones :)
Diffstat (limited to 'src/dged')
-rw-r--r--src/dged/buffer.c3
-rw-r--r--src/dged/settings.c13
-rw-r--r--src/dged/text.c7
-rw-r--r--src/dged/vec.h2
4 files changed, 21 insertions, 4 deletions
diff --git a/src/dged/buffer.c b/src/dged/buffer.c
index d25297f..ab86dc6 100644
--- a/src/dged/buffer.c
+++ b/src/dged/buffer.c
@@ -837,6 +837,9 @@ void buffer_find(struct buffer *buffer, const char *pattern,
*matches = VEC_ENTRIES(&data.matches);
*nmatches = VEC_SIZE(&data.matches);
+
+ VEC_DISOWN_ENTRIES(&data.matches);
+ VEC_DESTROY(&data.matches);
}
struct location buffer_copy(struct buffer *buffer, struct region region) {
diff --git a/src/dged/settings.c b/src/dged/settings.c
index df3af1c..3dc92ef 100644
--- a/src/dged/settings.c
+++ b/src/dged/settings.c
@@ -63,7 +63,6 @@ struct setting *settings_get(const char *path) {
void settings_get_prefix(const char *prefix, struct setting **settings_out[],
uint32_t *nsettings_out) {
- uint32_t capacity = 16;
VEC(struct setting *) res;
VEC_INIT(&res, 16);
HASHMAP_FOR_EACH(&g_settings.settings, struct setting_entry * entry) {
@@ -75,6 +74,9 @@ void settings_get_prefix(const char *prefix, struct setting **settings_out[],
*nsettings_out = VEC_SIZE(&res);
*settings_out = VEC_ENTRIES(&res);
+
+ VEC_DISOWN_ENTRIES(&res);
+ VEC_DESTROY(&res);
}
void settings_set(const char *path, struct setting_value value) {
@@ -194,13 +196,18 @@ static int32_t parse_toml(struct parser *state, char **errmsgs[]) {
free(curkey);
}
+ uint32_t ret = 0;
if (!VEC_EMPTY(&errs)) {
*errmsgs = VEC_ENTRIES(&errs);
+ ret = VEC_SIZE(&errs);
+
+ VEC_DISOWN_ENTRIES(&errs);
+ VEC_DESTROY(&errs);
} else {
*errmsgs = NULL;
VEC_DESTROY(&errs);
}
- return VEC_SIZE(&errs);
+ return ret;
}
struct str_cursor {
@@ -272,7 +279,7 @@ static size_t get_bytes_from_file(size_t nbytes, uint8_t *buf, void *userdata) {
memcpy(buf, r->buffer, to_read);
r->buflen -= to_read;
- memcpy(r->buffer, r->buffer + to_read, r->buflen);
+ memmove(r->buffer, r->buffer + to_read, r->buflen);
return to_read;
}
diff --git a/src/dged/text.c b/src/dged/text.c
index 0a92933..82c49bc 100644
--- a/src/dged/text.c
+++ b/src/dged/text.c
@@ -77,9 +77,14 @@ void text_clear(struct text *text) {
// given `char_idx` as a character index, return the byte index
uint32_t charidx_to_byteidx(struct line *line, uint32_t char_idx) {
+ if (line->nchars == 0) {
+ return 0;
+ }
+
if (char_idx > line->nchars) {
- return line->nbytes;
+ return line->nbytes - 1;
}
+
return utf8_nbytes(line->data, line->nbytes, char_idx);
}
diff --git a/src/dged/vec.h b/src/dged/vec.h
index 8b17fa5..929c8d5 100644
--- a/src/dged/vec.h
+++ b/src/dged/vec.h
@@ -17,6 +17,8 @@
(vec)->capacity = initial_capacity; \
(vec)->nentries = 0;
+#define VEC_DISOWN_ENTRIES(vec) (vec)->entries = NULL;
+
#define VEC_DESTROY(vec) \
free((vec)->temp); \
free((vec)->entries); \