mirror of
https://github.com/MidnightCommander/mc
synced 2025-01-03 18:14:25 +03:00
cleanup: moved int to size_t
Signed-off-by: Sergei Trofimovich <slyfox@inbox.ru>
This commit is contained in:
parent
6c016bc781
commit
6b6d4a222d
14
src/util.c
14
src/util.c
@ -230,10 +230,10 @@ fake_name_quote (const char *s, int quote_percent)
|
|||||||
* Return static buffer, no need to free() it.
|
* Return static buffer, no need to free() it.
|
||||||
*/
|
*/
|
||||||
const char *
|
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];
|
static char x[MC_MAXPATHLEN + MC_MAXPATHLEN];
|
||||||
int txt_len;
|
size_t txt_len;
|
||||||
char *p;
|
char *p;
|
||||||
|
|
||||||
if (!txt)
|
if (!txt)
|
||||||
@ -241,16 +241,16 @@ name_trunc (const char *txt, int trunc_len)
|
|||||||
if (!*txt)
|
if (!*txt)
|
||||||
return txt;
|
return txt;
|
||||||
|
|
||||||
if ((size_t) trunc_len > sizeof (x) - 1) {
|
if (trunc_len > sizeof (x) - 1) {
|
||||||
trunc_len = sizeof (x) - 1;
|
trunc_len = sizeof (x) - 1;
|
||||||
}
|
}
|
||||||
txt_len = (int) strlen (txt);
|
txt_len = strlen (txt);
|
||||||
if (txt_len <= trunc_len) {
|
if (txt_len <= trunc_len) {
|
||||||
strcpy (x, txt);
|
strcpy (x, txt);
|
||||||
} else {
|
} else {
|
||||||
int y = (trunc_len / 2) + (trunc_len % 2);
|
size_t y = (trunc_len / 2) + (trunc_len % 2);
|
||||||
strncpy (x, txt, (size_t) y);
|
strncpy (x, txt, (size_t) y);
|
||||||
strncpy (x + y, txt + (size_t) (txt_len - (trunc_len / 2)), (size_t) trunc_len / 2);
|
strncpy (x + y, txt + (txt_len - (trunc_len / 2)), trunc_len / 2);
|
||||||
x[y] = '~';
|
x[y] = '~';
|
||||||
}
|
}
|
||||||
x[trunc_len] = 0;
|
x[trunc_len] = 0;
|
||||||
@ -266,7 +266,7 @@ name_trunc (const char *txt, int trunc_len)
|
|||||||
* reasons.
|
* reasons.
|
||||||
*/
|
*/
|
||||||
const char *
|
const char *
|
||||||
path_trunc (const char *path, int trunc_len) {
|
path_trunc (const char *path, size_t trunc_len) {
|
||||||
const char *ret;
|
const char *ret;
|
||||||
char *secure_path = strip_password (g_strdup (path), 1);
|
char *secure_path = strip_password (g_strdup (path), 1);
|
||||||
|
|
||||||
|
@ -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.
|
/* Remove the middle part of the string to fit given length.
|
||||||
* Use "~" to show where the string was truncated.
|
* Use "~" to show where the string was truncated.
|
||||||
* Return static buffer, no need to free() it. */
|
* 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
|
/* path_trunc() is the same as name_trunc() above but
|
||||||
* it deletes possible password from path for security
|
* it deletes possible password from path for security
|
||||||
* reasons. */
|
* 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
|
/* return a static string representing size, appending "K" or "M" for
|
||||||
* big sizes.
|
* big sizes.
|
||||||
|
Loading…
Reference in New Issue
Block a user