mirror of
https://github.com/MidnightCommander/mc
synced 2025-03-12 19:03:10 +03:00
* 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:
parent
d6575d196a
commit
1314fc2a07
@ -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>
|
||||
|
||||
* screen.c (string_file_name): Fix possible off-by-one
|
||||
|
@ -728,7 +728,8 @@ show_dir (WPanel *panel)
|
||||
|
||||
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);
|
||||
widget_move (&panel->widget, 0, 1);
|
||||
addstr ("<");
|
||||
|
28
src/util.c
28
src/util.c
@ -107,15 +107,27 @@ int msglen (char *text, int *lines)
|
||||
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);
|
||||
|
||||
if (source_len > len){
|
||||
strcpy (d, s+(source_len-len));
|
||||
d [0] = '.';
|
||||
d [1] = '.';
|
||||
d [2] = '.';
|
||||
int source_len;
|
||||
|
||||
if (len < 3) {
|
||||
len = max (len, 0);
|
||||
memset (d, '.', len);
|
||||
d[len] = 0;
|
||||
return d;
|
||||
}
|
||||
|
||||
source_len = strlen (s);
|
||||
if (source_len > len) {
|
||||
memset (d, '.', 3);
|
||||
strcpy (d + 3, s + 3 + source_len - len);
|
||||
} else
|
||||
strcpy (d, s);
|
||||
return d;
|
||||
|
Loading…
x
Reference in New Issue
Block a user