X-Git-Url: https://diplodocus.org/git/nmh/blobdiff_plain/92128dacf8d5db02379e8f872dc50d31c6aaa55f..cdec1be974fb9a041d75d4e363463e58766309b3:/sbr/fmt_scan.c diff --git a/sbr/fmt_scan.c b/sbr/fmt_scan.c index 998d3938..08405da1 100644 --- a/sbr/fmt_scan.c +++ b/sbr/fmt_scan.c @@ -144,7 +144,7 @@ cptrimmed(charstring_t dest, char *str, int wid, char fill, size_t max) { if ((sp = str)) { #ifdef MULTIBYTE_SUPPORT - mbtowc(NULL, NULL, 0); /* reset shift state */ + if (mbtowc(NULL, NULL, 0)) {} /* reset shift state */ #endif end = strlen(str); while (*sp && remaining > 0 && end > 0) { @@ -252,7 +252,7 @@ cpstripped (charstring_t dest, size_t max, char *str) len = strlen(str); #ifdef MULTIBYTE_SUPPORT - mbtowc(NULL, NULL, 0); /* Reset shift state */ + if (mbtowc(NULL, NULL, 0)) {} /* Reset shift state */ #endif /* MULTIBYTE_SUPPORT */ /* @@ -380,15 +380,8 @@ fmt_scan (struct format *format, charstring_t scanlp, int width, int *dat, struct mailname *mn; /* - * The newline counts in the display width, for backward - * compatibility. To change that so that the newline doesn't - * count, remove the following statement. - */ - --width; - - /* - * max is the same as width, but unsigned. So comparisons - * with charstring_chars() won't raise compile warning. + * max is the same as width, but unsigned so comparisons + * with charstring_chars() won't raise compile warnings. */ max = width; savestr = str = NULL; @@ -506,6 +499,9 @@ fmt_scan (struct format *format, charstring_t scanlp, int width, int *dat, if (val < scale) { snprintf(buffer, sizeof(buffer), "%u", val); } else { + /* To prevent divide by 0, found by clang static + analyzer. */ + if (scale == 0) { scale = 1; } /* find correct scale for size (Kilo/Mega/Giga/Tera) */ for (unitcp = "KMGT"; val > (scale * scale); val /= scale) { @@ -828,6 +824,7 @@ fmt_scan (struct format *format, charstring_t scanlp, int width, int *dat, default: value = -1; break; } + break; case FT_LV_ZONEF: if ((fmt->f_comp->c_tws->tw_flags & TW_SZONE) == TW_SZEXP) value = 1; @@ -995,7 +992,7 @@ fmt_scan (struct format *format, charstring_t scanlp, int width, int *dat, lp = str; wid = value; - len = strlen (str); + len = str ? strlen (str) : 0; sp = fmt->f_text; indent = strlen (sp); wid -= indent;