From c293f725e55661ae690b52d5e8339e48b07a6a85 Mon Sep 17 00:00:00 2001 From: Robin Haberkorn Date: Sun, 22 Dec 2024 18:08:14 +0300 Subject: fixed crashes while setting special Q-Registers with EU (string-building characters) * The teco_qreg_vtable_t::get_string() method should support returning the length optionally (may be NULL). This already worked with teco_doc_get_string(), even though it wasn't documented, and therefore didn't cause problems with regular Q-Registers. --- src/doc.c | 3 ++- src/qreg.c | 12 ++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/doc.c b/src/doc.c index a1ebe2c..019603a 100644 --- a/src/doc.c +++ b/src/doc.c @@ -176,7 +176,8 @@ teco_doc_undo_set_string(teco_doc_t *ctx) * @param str Pointer to a variable to hold the return string. * It can be NULL if you are interested only in the string's length. * Strings must be freed via g_free(). - * @param len Where to store the string's length (mandatory). + * @param len Where to store the string's length or NULL + * if that information is not necessary. * @param codepage Where to store the document's codepage or NULL * if that information is not necessary. * diff --git a/src/qreg.c b/src/qreg.c index 061b685..91ee630 100644 --- a/src/qreg.c +++ b/src/qreg.c @@ -665,9 +665,6 @@ teco_qreg_bufferinfo_append_string(teco_qreg_t *qreg, const gchar *str, gsize le return FALSE; } -/* - * NOTE: The `string` component is currently unused on the "*" register. - */ static gboolean teco_qreg_bufferinfo_get_string(teco_qreg_t *qreg, gchar **str, gsize *len, guint *codepage, GError **error) @@ -684,7 +681,8 @@ teco_qreg_bufferinfo_get_string(teco_qreg_t *qreg, gchar **str, gsize *len, /* * NOTE: teco_file_normalize_path() does not change the size of the string. */ - *len = teco_ring_current->filename ? strlen(teco_ring_current->filename) : 0; + if (len) + *len = teco_ring_current->filename ? strlen(teco_ring_current->filename) : 0; if (codepage) *codepage = teco_default_codepage(); return TRUE; @@ -775,7 +773,8 @@ teco_qreg_workingdir_get_string(teco_qreg_t *qreg, gchar **str, gsize *len, * the return value for str == NULL is still correct. */ gchar *dir = g_get_current_dir(); - *len = strlen(dir); + if (len) + *len = strlen(dir); if (str) *str = teco_file_normalize_path(dir); else @@ -919,11 +918,12 @@ teco_qreg_clipboard_get_string(teco_qreg_t *qreg, gchar **str, gsize *len, &str_converted.len, error) == G_IO_STATUS_ERROR) return FALSE; + if (len) + *len = str_converted.len; if (str) *str = str_converted.data; else teco_string_clear(&str_converted); - *len = str_converted.len; if (codepage) *codepage = teco_default_codepage(); -- cgit v1.2.3