[Pkg-octave-devel] Bug#485920: [patch] Re: waitbar() crashing when used from within emacs
On 20/06/08 10:17 -0500, Quentin Spencer wrote:
> Thomas Weber wrote:
>> Am Donnerstag, den 12.06.2008, 12:44 +0200 schrieb Thomas Weber:
>>
>>> Hi,
>>>
>>> starting an octave-inferior process within Emacs and then using the
>>> waitbar function from miscellaneous crashes octave:
>>>
>>> octave> waitbar(0)
>>> panic: Segmentation fault -- stopping myself...
>>> attempting to save variables to `octave-core'...
>>> save to `octave-core' complete
>>>
>>> Process Inferior Octave segmentation fault
>>>
>>>
>>> The crash happens in line 150 where buf_ptr is a null pointer. The
>>> problematic part is however in line 147 already, where tgetstr() returns
>>> 0. Excerpt from tgetstr()'s man page:
>>>
>>> "The tgetstr routine returns the string entry for id, or zero if it is
>>> not available."
>>>
>>> I don't know if it's possible to change waitbar() to work from within
>>> Emacs.
>>>
>>> Thomas
>>>
>
>
> It has been a long time since I wrote this. If I recall correctly, the
> purpose of this was to get the width of the terminal, which apparently
> does not work inside emacs. The fix is probably to deal with zero output
> correctly, probably just forcing it to use the parts of the code where
> it defaults to some fixed width if it can't figure out how wide it
> should be.
I took a closer look at the code. The part in question implements a progress
bar by switching into standout mode (tgetstr("so", &buf_ptr);) and back out
from standout mode (tgetstr("se", &buf_ptr);)
Emacs doesn't seem to handle this, but as there is a progress reporter in
percent, the attached patch simply protects the null pointer dereference (the
patch looks bigger than it is, as I adjusted the indendation accordinly).
Thomas
Index: main/miscellaneous/src/waitbar.cc
===================================================================
--- main/miscellaneous/src/waitbar.cc (revision 5132)
+++ main/miscellaneous/src/waitbar.cc (working copy)
@@ -146,11 +146,18 @@
char* buf_ptr = term_buffer;
begin_rv = tgetstr("so", &buf_ptr);
end_rv = tgetstr("se", &buf_ptr);
- brvlen = 0; buf_ptr = begin_rv;
- while(buf_ptr[++brvlen]);
- ervlen = 0; buf_ptr = end_rv;
- while(buf_ptr[++ervlen]);
+ // Display a progress bar, but only if the current terminal has a
+ // standout mode
+ if (begin_rv && end_rv)
+ {
+ brvlen = 0;
+ buf_ptr = begin_rv;
+ while(buf_ptr[++brvlen]);
+ ervlen = 0; buf_ptr = end_rv;
+ while(buf_ptr[++ervlen]);
+ }
+
// initialize print buffer
for(i=0; i<BUF_SIZE; ++i)
print_buf[i] = ' ';
Reply to: