[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Bug-apl] About aplwrap

From: Chris Moller
Subject: Re: [Bug-apl] About aplwrap
Date: Tue, 29 Mar 2016 19:27:59 -0400
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.7.0

Hi, y'all,

I just stuck this patch in.  It works fine for me, but, Christian, if you could try it in your environment, I'd appreciate it.

Chris  (also, BTW, "Christian" who happens to have a son named Robert Christian Moller)

On 03/29/16 18:42, Christian Robert wrote:
Hi Chris,

  I found a bug in https://github.com/ChrisMoller/aplwrap/blob/master/src/txtbuf.c
  The bug randomly make aplwrap to coredump, especially if you yse the copy down
  feature. Look for the word "HERE" below ...

handle_copy_down ()
  GtkTextIter start_iter, end_iter;
  if (gtk_text_buffer_get_selection_bounds (buffer, &start_iter, &end_iter)) {
    //  Case 1: selection is not empty
    //  If selection does not span newline
    //    copy selection to end of buffer
    //    If selection does not end with a space
    //      append a space to end of buffer
    //    *Do not* scroll to end!
    gchar *text = gtk_text_buffer_get_text (buffer,
    if (text == NULL || strchr (text, '\n')) return 0;

    gtk_text_buffer_get_end_iter (buffer, &end_iter);
    gtk_text_buffer_place_cursor (buffer, &end_iter);
    gtk_text_buffer_insert_at_cursor (buffer, text, -1);
    if (text[strlen(text)-1] != ' ')
      gtk_text_buffer_insert_at_cursor (buffer, " ", -1);

    g_free (text);
    return 1;
  else {
    //  Case 2: selection is empty
    //  If cursor is in previous input
    //    copy previous input to end of buffer
    //    scroll to end of buffer
    GtkTextIter insert_iter;
    GtkTextMark *mark = gtk_text_buffer_get_insert (buffer);
    gtk_text_buffer_get_iter_at_mark (buffer, &insert_iter, mark);
    if (gtk_text_iter_has_tag (&insert_iter, get_tag(TAG_INP))) {
      gint sz;
      gchar *text = get_input_text (&sz);
      gchar *ztext = g_try_malloc (sz+1-6);
      if (ztext) {
        memcpy(ztext, text+6, sz-6);
        ztext[sz] = '\0';                            //  <--- *HERE*
        handle_history_replacement (ztext);
        g_free (ztext);
      return 1;
    else if (gtk_text_iter_has_tag (&insert_iter, get_tag(TAG_LCK)))
      return 1;
    return 0;

should be:

   ztext[sz-6] = '\0';

or better, delete that line, the memcpy() above always include the final '\0', I've traced it.

thanks for committing that change.

Christian Robert,

reply via email to

[Prev in Thread] Current Thread [Next in Thread]