mirror of https://github.com/MidnightCommander/mc
fixed name_trunc() on NULL or empty strings - patch from andrew_b
This commit is contained in:
parent
5ee6f43796
commit
6c016bc781
|
@ -1,3 +1,8 @@
|
|||
2009-02-01 Enrico Weigelt, metux ITS <weigelt@metux.de>
|
||||
|
||||
* src/util.c: fixed name_trunc() on NULL or empty parameters
|
||||
(patch from andrew_b)
|
||||
|
||||
2009-01-31 Enrico Weigelt, metux ITS <weigelt@metux.de>, Patrick Winnertz <winnie@debian.org>, Slava Zanko <slavazanko@gmail.com>, Sergei Trofimovich <slyfox@inbox.ru>
|
||||
|
||||
* edit/editcmd.c, mhl/escape.h, mhl/string.h, mhl/types.h, src/Makefile.am,
|
||||
|
|
11
src/util.c
11
src/util.c
|
@ -236,16 +236,21 @@ name_trunc (const char *txt, int trunc_len)
|
|||
int txt_len;
|
||||
char *p;
|
||||
|
||||
if (!txt)
|
||||
return NULL;
|
||||
if (!*txt)
|
||||
return txt;
|
||||
|
||||
if ((size_t) trunc_len > sizeof (x) - 1) {
|
||||
trunc_len = sizeof (x) - 1;
|
||||
}
|
||||
txt_len = strlen (txt);
|
||||
txt_len = (int) strlen (txt);
|
||||
if (txt_len <= trunc_len) {
|
||||
strcpy (x, txt);
|
||||
} else {
|
||||
int y = (trunc_len / 2) + (trunc_len % 2);
|
||||
strncpy (x, txt, y);
|
||||
strncpy (x + y, txt + txt_len - (trunc_len / 2), trunc_len / 2);
|
||||
strncpy (x, txt, (size_t) y);
|
||||
strncpy (x + y, txt + (size_t) (txt_len - (trunc_len / 2)), (size_t) trunc_len / 2);
|
||||
x[y] = '~';
|
||||
}
|
||||
x[trunc_len] = 0;
|
||||
|
|
Loading…
Reference in New Issue