]> diplodocus.org Git - nmh/blobdiff - sbr/fmt_scan.c
mhn.defaults: make fetch less agressive on FreeBSD.
[nmh] / sbr / fmt_scan.c
index 47a5fe87ecb83ddc890617fc4ef979b0bba024a0..08405da1e00158842740f67dda8f63814551315d 100644 (file)
@@ -144,7 +144,7 @@ cptrimmed(charstring_t dest, char *str, int wid, char fill, size_t max) {
 
     if ((sp = str)) {
 #ifdef MULTIBYTE_SUPPORT
 
     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) {
 #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
     len = strlen(str);
 
 #ifdef MULTIBYTE_SUPPORT
-    mbtowc(NULL, NULL, 0);  /* Reset shift state */
+    if (mbtowc(NULL, NULL, 0)) {}  /* Reset shift state */
 #endif /* MULTIBYTE_SUPPORT */
 
     /*
 #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 {
                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) {
 
                    /* 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;
            }
                default:
                    value = -1; break;
            }
+           break;
        case FT_LV_ZONEF:
            if ((fmt->f_comp->c_tws->tw_flags & TW_SZONE) == TW_SZEXP)
                    value = 1;
        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;
 
            lp = str;
            wid = value;
-           len = strlen (str);
+           len = str ? strlen (str) : 0;
            sp = fmt->f_text;
            indent = strlen (sp);
            wid -= indent;
            sp = fmt->f_text;
            indent = strlen (sp);
            wid -= indent;