Re: show_dir crashes on more than 200 columns
- From: Jindrich Novy <jnovy redhat com>
- To: Pavel Tsekov <ptsekov gmx net>
- Cc: MC Devel <mc-devel gnome org>, Leonard den Ottolander <leonard den ottolander nl>
- Subject: Re: show_dir crashes on more than 200 columns
- Date: Wed, 03 Nov 2004 15:55:45 +0100
Hello Leonard, Pavel,
On Wed, 2004-11-03 at 12:50, Pavel Tsekov wrote:
> Hello,
>
> On Wed, 3 Nov 2004, Leonard den Ottolander wrote:
>
> > A small fix to avoid a crash in show_dir() with a panel of more than 200
> > columns. Thanks to Vladimir.
> >
> > (Jindrich, a g_malloc0 and a free of tmp[] seem rather redundant here.)
>
> No, it is not. You cannot rely on MC_MAXPATHLEN - it can be too small or
> too big. For exmaple on Cygwin it is set to 259 . I remeber I've seen
> also pretty big values for MAXPATHLEN which are not suitable for
> allocating on the stack. Use the `widget.cols' and allocate memory from
> the heap.
The widget.cols is IMHO the best solution since we're not wasting any
memory. Corrected patch attached.
greetings,
Jindrich
--
Jindrich Novy <jnovy redhat com>, http://people.redhat.com/jnovy/
--- mc-4.6.1-20041103/src/screen.c.jn 2004-09-24 17:05:28.000000000 +0200
+++ mc-4.6.1-20041103/src/screen.c 2004-11-03 15:45:15.887242808 +0100
@@ -728,7 +728,7 @@ mini_info_separator (WPanel *panel)
static void
show_dir (WPanel *panel)
{
- char tmp[200];
+ char *tmp;
set_colors (panel);
draw_double_box (panel->widget.parent,
@@ -750,9 +750,14 @@ show_dir (WPanel *panel)
widget_move (&panel->widget, 0, 3);
+ tmp = g_malloc (panel->widget.cols + 1);
+ tmp[panel->widget.cols] = '\0';
+
trim (strip_home_and_password (panel->cwd), tmp,
- max (panel->widget.cols - 7, 0));
+ min (max (panel->widget.cols - 7, 0), panel->widget.cols) );
+
addstr (tmp);
+ g_free (tmp);
widget_move (&panel->widget, 0, 1);
addstr ("<");
widget_move (&panel->widget, 0, panel->widget.cols - 2);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]