]> xenbits.xensource.com Git - people/pauldu/mini-os.git/commitdiff
mini-os: fix coverity issues in printf.c
authorJuergen Gross <jgross@suse.com>
Wed, 17 Aug 2016 13:39:59 +0000 (15:39 +0200)
committerWei Liu <wei.liu2@citrix.com>
Mon, 22 Aug 2016 09:37:26 +0000 (10:37 +0100)
Fix two issues discovered by Coverity:

1. properly mark one switch case as fall-through
2. unroll a loop that only executes once

CID: 1369623
CID: 1019001

Signed-off-by: Juergen Gross <jgross@suse.com>
Reviewed-by: Wei Liu <wei.liu2@citrix.com>
Acked-by: Samuel Thibault <samuel.thibautl@ens-lyon.org>
lib/printf.c

index ad6a304920220f062c050e780e9e147c2ee6b592..f9e9d682eea3ee16a8cdeefc27b2eae0991779fa 100644 (file)
@@ -379,6 +379,7 @@ reswitch:       switch (ch = (u_char)*fmt++) {
                                 padc = '0';
                                 goto reswitch;
                         }
+                        /* fallthrough */
                 case '1': case '2': case '3': case '4':
                 case '5': case '6': case '7': case '8': case '9':
                                 for (n = 0;; ++fmt) {
@@ -966,20 +967,16 @@ literal:
                                 width = 1;
                         if (flags & SUPPRESS) {
                                 size_t sum = 0;
-                                for (;;) {
-                                        if ((n = inr) < width) {
-                                                sum += n;
-                                                width -= n;
-                                                inp += n;
-                                                if (sum == 0)
-                                                        goto input_failure;
-                                                break;
-                                        } else {
-                                                sum += width;
-                                                inr -= width;
-                                                inp += width;
-                                                break;
-                                        }
+                                if ((n = inr) < width) {
+                                        sum += n;
+                                        width -= n;
+                                        inp += n;
+                                        if (sum == 0)
+                                                goto input_failure;
+                                } else {
+                                        sum += width;
+                                        inr -= width;
+                                        inp += width;
                                 }
                                 nread += sum;
                         } else {