bug-indent
[Top][All Lists]
Advanced

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

Segfault in current_column()?


From: Warren DeLano
Subject: Segfault in current_column()?
Date: Sun, 14 Jun 2009 15:08:42 -0700

indent developers:

I believe there is a flaw in the current_column routine inside
code_io.c, because when p is assigned to cur_line, the while-loop which
tests p against buf_ptr will result in segmentation fault since cur_line
is inside a different buffer context than buf_ptr...at least as far I
can tell with gdb.

My naive solution is included below (adapted from the 2.2.10).  I
introduce a "once" flag which forces a single pass through the switch
statement when p is assigned to cur_line.

This change eliminates the segmentation faults I was experiencing with
my C code, but I have no understanding of whether it makes sense in the
larger context of how indent works.

Hope this helps! 

Cheers,
Warren

int current_column (void)
{
    char *p;
    int column;
    int once = false;
    /* Use save_com.size here instead of save_com.end, because save_com
is
     * already emptied at this point. */
  
    if ((buf_ptr >= save_com.ptr) && (buf_ptr <= save_com.ptr +
save_com.len))
    {
        p = save_com.ptr;
        column = save_com.start_column;
    }
    else
    {
        p = cur_line;
        column = 1;
        once = true;
    }

    while (p < buf_ptr)
    {
        switch (*p)
        {
            case EOL:
            case 014:           /* form feed */
                column = 1;
                break;

            case TAB:
                column += settings.tabsize - (column - 1) %
settings.tabsize;
                break;

            case '\b':          /* backspace */
                column--;
                break;

            default:
                column++;
                break;
        }
        if(once)
          break;
        p++;
    }
    return column;
}







reply via email to

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