From e3d457eb3d08392bd8237397a3f96a640134e50e Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Tue, 8 Nov 2016 13:19:29 +0300 Subject: [PATCH] Revert "Ticket #3666: (size_trunc_len): fix segfault because of small buffer usage." This reverts commit 3024f309c2bf8c8932ede1cbc43bf478bd631f6f. --- lib/util.c | 10 ++++------ lib/util.h | 3 +-- src/viewer/display.c | 6 ++++-- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/lib/util.c b/lib/util.c index f89ea571a..3356c36f3 100644 --- a/lib/util.c +++ b/lib/util.c @@ -402,10 +402,10 @@ size_trunc_sep (uintmax_t size, gboolean use_si) /* --------------------------------------------------------------------------------------------- */ /** - * Print file SIZE to BUFFER, but don't exceed LEN characters, not including trailing 0. - * LEN should be at least 7 long and BUFFER at least LEN+1 long. - * - * This function is called for every file on panels, so avoid floating point by any means. + * Print file SIZE to BUFFER, but don't exceed LEN characters, + * not including trailing 0. BUFFER should be at least LEN+1 long. + * This function is called for every file on panels, so avoid + * floating point by any means. * * Units: size units (filesystem sizes are 1K blocks) * 0=bytes, 1=Kbytes, 2=Mbytes, etc. @@ -458,8 +458,6 @@ size_trunc_len (char *buffer, unsigned int len, uintmax_t size, int units, gbool const char *const *sfx = use_si ? units_si : units_iec; int j = 0; - g_assert (len >= 7); - if (len == 0) len = 9; #if SIZEOF_UINTMAX_T == 8 diff --git a/lib/util.h b/lib/util.h index db1fae2b6..af4022ee7 100644 --- a/lib/util.h +++ b/lib/util.h @@ -147,8 +147,7 @@ const char *size_trunc (uintmax_t size, gboolean use_si); const char *size_trunc_sep (uintmax_t size, gboolean use_si); /* Print file SIZE to BUFFER, but don't exceed LEN characters, - * not including trailing 0. LEN should be at least 7 long - * and BUFFER at least LEN+1 long. + * not including trailing 0. BUFFER should be at least LEN+1 long. * * Units: size units (0=bytes, 1=Kbytes, 2=Mbytes, etc.) */ void size_trunc_len (char *buffer, unsigned int len, uintmax_t size, int units, gboolean use_si); diff --git a/src/viewer/display.c b/src/viewer/display.c index d662f9be1..40e57a64e 100644 --- a/src/viewer/display.c +++ b/src/viewer/display.c @@ -56,6 +56,8 @@ /*** file scope macro definitions ****************************************************************/ +#define BUF_TRUNC_LEN 5 /* The length of the line displays the file size */ + /*** file scope type declarations ****************************************************************/ /*** file scope variables ************************************************************************/ @@ -170,9 +172,9 @@ mcview_display_status (WView * view) tty_printf ("0x%08" PRIxMAX, (uintmax_t) view->hex_cursor); else { - char buffer[12]; + char buffer[BUF_TRUNC_LEN + 1]; - size_trunc_len (buffer, sizeof (buffer) - 1, mcview_get_filesize (view), 0, + size_trunc_len (buffer, BUF_TRUNC_LEN, mcview_get_filesize (view), 0, panels_options.kilobyte_si); tty_printf ("%9" PRIuMAX "/%s%s %s", (uintmax_t) view->dpy_end, buffer, mcview_may_still_grow (view) ? "+" : " ", -- 2.11.4.GIT