Skip to content

Commit

Permalink
Adapt to SCI_GETTEXT changes
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kugel- committed Dec 7, 2021
1 parent c603bbf commit d7c985e
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/sciwrappers.c
Expand Up @@ -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';
}
}


Expand All @@ -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;
}

Expand All @@ -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. */
Expand Down

0 comments on commit d7c985e

Please sign in to comment.