X-Git-Url: https://diplodocus.org/git/nmh/blobdiff_plain/e537b780f7aea8df01ddca1976f8c128d9c1fb55..cdec1be974fb9a041d75d4e363463e58766309b3:/sbr/fmt_scan.c?ds=inline diff --git a/sbr/fmt_scan.c b/sbr/fmt_scan.c index 47a5fe87..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 */ /* @@ -499,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) { @@ -821,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; @@ -988,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;