Merge commit 'origin/230_fix_name_trunc' into mc-4.6

This commit is contained in:
Enrico Weigelt, metux IT service 2009-02-01 22:05:17 +01:00
commit c76c6e5ffc
3 changed files with 19 additions and 9 deletions

View File

@ -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,

View File

@ -230,22 +230,27 @@ fake_name_quote (const char *s, int quote_percent)
* Return static buffer, no need to free() it.
*/
const char *
name_trunc (const char *txt, int trunc_len)
name_trunc (const char *txt, size_t trunc_len)
{
static char x[MC_MAXPATHLEN + MC_MAXPATHLEN];
int txt_len;
size_t txt_len;
char *p;
if ((size_t) trunc_len > sizeof (x) - 1) {
if (!txt)
return NULL;
if (!*txt)
return txt;
if (trunc_len > sizeof (x) - 1) {
trunc_len = sizeof (x) - 1;
}
txt_len = 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);
size_t y = (trunc_len / 2) + (trunc_len % 2);
strncpy (x, txt, (size_t) y);
strncpy (x + y, txt + (txt_len - (trunc_len / 2)), trunc_len / 2);
x[y] = '~';
}
x[trunc_len] = 0;
@ -261,7 +266,7 @@ name_trunc (const char *txt, int trunc_len)
* reasons.
*/
const char *
path_trunc (const char *path, int trunc_len) {
path_trunc (const char *path, size_t trunc_len) {
const char *ret;
char *secure_path = strip_password (g_strdup (path), 1);

View File

@ -34,12 +34,12 @@ char *fake_name_quote (const char *c, int quote_percent);
/* Remove the middle part of the string to fit given length.
* Use "~" to show where the string was truncated.
* Return static buffer, no need to free() it. */
const char *name_trunc (const char *txt, int trunc_len);
const char *name_trunc (const char *txt, size_t trunc_len);
/* path_trunc() is the same as name_trunc() above but
* it deletes possible password from path for security
* reasons. */
const char *path_trunc (const char *path, int trunc_len);
const char *path_trunc (const char *path, size_t trunc_len);
/* return a static string representing size, appending "K" or "M" for
* big sizes.