[geany/geany] d7c985: Adapt to SCI_GETTEXT changes

Thomas Martitz git-noreply at xxxxx
Sun Jan 9 22:50:44 UTC 2022


Branch:      refs/heads/master
Author:      Thomas Martitz <thomas.martitz at mailbox.org>
Committer:   Thomas Martitz <thomas.martitz at mailbox.org>
Date:        Tue, 07 Dec 2021 15:26:03 UTC
Commit:      d7c985e47412f8a53c5a8202a0f8b669c4fd5e08
             https://github.com/geany/geany/commit/d7c985e47412f8a53c5a8202a0f8b669c4fd5e08

Log Message:
-----------
Adapt to SCI_GETTEXT changes

SCI_GETTEXT second parameter, the buffer length, does not account
for the NUL termination anymore. Therefore, take care to not tell
Scintilla to overwrite the last byte reserved for NUL termination.


Modified Paths:
--------------
    src/sciwrappers.c

Modified: src/sciwrappers.c
18 lines changed, 14 insertions(+), 4 deletions(-)
===================================================================
@@ -730,7 +730,10 @@ gchar *sci_get_line(ScintillaObject *sci, gint line_num)
 GEANY_API_SYMBOL
 void sci_get_text(ScintillaObject *sci, gint len, gchar *text)
 {
-	SSM(sci, SCI_GETTEXT, (uptr_t) len, (sptr_t) text);
+	if (len > 0) {
+		SSM(sci, SCI_GETTEXT, (uptr_t) len - 1, (sptr_t) text);
+		text[len] = '\0';
+	}
 }
 
 
@@ -749,10 +752,14 @@ gchar *sci_get_contents(ScintillaObject *sci, gint buffer_len)
 	gchar *text;
 
 	if (buffer_len < 0)
-		buffer_len = sci_get_length(sci) + 1;
+		return sci_get_string(sci, SCI_GETTEXT, 0);
 
-	text = g_malloc(buffer_len);
-	SSM(sci, SCI_GETTEXT, (uptr_t) buffer_len, (sptr_t) text);
+	text = NULL;
+	if (buffer_len > 0) {
+		text = g_malloc(buffer_len);
+		sci_get_text(sci, buffer_len - 1, text);
+		text[buffer_len - 1] = '\0';
+	}
 	return text;
 }
 
@@ -761,6 +768,9 @@ gchar *sci_get_contents(ScintillaObject *sci, gint buffer_len)
  * @deprecated sci_get_selected_text is deprecated and should not be used in newly-written code.
  * Use sci_get_selection_contents() instead.
  *
+ * @note You must ensure NUL termination yourself, this function does
+ * not NUL terminate the buffer itself.
+ *
  * @param sci Scintilla widget.
  * @param text Text buffer; must be allocated sci_get_selected_text_length() + 1 bytes
  * for null-termination. */



--------------
This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).


More information about the Commits mailing list