[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] [mini-os master] mini-os: fix coverity issues in printf.c



commit 4c16157118682ead45dde790e503b4f1a187d5e8
Author:     Juergen Gross <jgross@xxxxxxxx>
AuthorDate: Wed Aug 17 15:39:59 2016 +0200
Commit:     Wei Liu <wei.liu2@xxxxxxxxxx>
CommitDate: Mon Aug 22 10:37:26 2016 +0100

    mini-os: fix coverity issues in printf.c
    
    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@xxxxxxxx>
    Reviewed-by: Wei Liu <wei.liu2@xxxxxxxxxx>
    Acked-by: Samuel Thibault <samuel.thibautl@xxxxxxxxxxxx>
---
 lib/printf.c | 25 +++++++++++--------------
 1 file changed, 11 insertions(+), 14 deletions(-)

diff --git a/lib/printf.c b/lib/printf.c
index ad6a304..f9e9d68 100644
--- a/lib/printf.c
+++ b/lib/printf.c
@@ -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 {
--
generated by git-patchbot for /home/xen/git/mini-os.git#master

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxx
https://lists.xenproject.org/xen-changelog

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.