* screen.c (show_dir): Don't call trim() with negative length.

* util.c (trim): Better handle short length.  Make sure that the
destination is always 0-terminated.
This commit is contained in:
Pavel Roskin 2002-09-10 19:58:33 +00:00
parent d6575d196a
commit 1314fc2a07
3 changed files with 28 additions and 9 deletions

View File

@ -1,3 +1,9 @@
2002-09-10 Pavel Roskin <proski@gnu.org>
* screen.c (show_dir): Don't call trim() with negative length.
* util.c (trim): Better handle short length. Make sure that the
destination is always 0-terminated.
2002-09-09 Andrew V. Samoilov <sav@bcs.zp.ua> 2002-09-09 Andrew V. Samoilov <sav@bcs.zp.ua>
* screen.c (string_file_name): Fix possible off-by-one * screen.c (string_file_name): Fix possible off-by-one

View File

@ -728,7 +728,8 @@ show_dir (WPanel *panel)
widget_move (&panel->widget, 0, 3); widget_move (&panel->widget, 0, 3);
trim (strip_home_and_password (panel->cwd), tmp, panel->widget.cols-7); trim (strip_home_and_password (panel->cwd), tmp,
max (panel->widget.cols - 7, 0));
addstr (tmp); addstr (tmp);
widget_move (&panel->widget, 0, 1); widget_move (&panel->widget, 0, 1);
addstr ("<"); addstr ("<");

View File

@ -107,15 +107,27 @@ int msglen (char *text, int *lines)
return max; return max;
} }
char *trim (char *s, char *d, int len) /*
* Copy from s to d, and trim the beginning if necessary, and prepend
* "..." in this case. The destination string can have at most len
* bytes, not counting trailing 0.
*/
char *
trim (char *s, char *d, int len)
{ {
int source_len = strlen (s); int source_len;
if (source_len > len){ if (len < 3) {
strcpy (d, s+(source_len-len)); len = max (len, 0);
d [0] = '.'; memset (d, '.', len);
d [1] = '.'; d[len] = 0;
d [2] = '.'; return d;
}
source_len = strlen (s);
if (source_len > len) {
memset (d, '.', 3);
strcpy (d + 3, s + 3 + source_len - len);
} else } else
strcpy (d, s); strcpy (d, s);
return d; return d;