Skip to contentSkip to conversation

mini-os: fix coverity issues in printf.c

PATCH In review Juergen Gross 3 participants 7 messages Aug 17, 2016 – Aug 22, 2016 Library code

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mini-os: fix coverity issues in printf.c

Fix two issues discovered by coverity.

---
 lib/printf.c | 25 +++++++++++--------------
 1 file changed, 11 insertions(+), 14 deletions(-)
lib/printf.c +11 -14
index ad6a304..f9e9d68 100644
@@ -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 {
Signature · 7 lines
2.6.6


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Reviewed-by on v1 1/1
#1 lore raw
Quoted 1 line · Juergen Gross

Fix two issues discovered by coverity.

I would update the commit message to make it contain more information.

Fix two issues discovered by Coverity:

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

CID: 1369623
CID: 1019001

Quoted 2 lines
Quoted 50 lines
---
 lib/printf.c | 25 +++++++++++--------------
 1 file changed, 11 insertions(+), 14 deletions(-)
lib/printf.c +11 -14
index ad6a304..f9e9d68 100644
@@ -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 {
Signature · 1 line
2.6.6

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#2 lore raw
Quoted 5 lines · Wei Liu
Quoted 1 line · Juergen Gross

Fix two issues discovered by coverity.

I would update the commit message to make it contain more information.

Quoted 7 lines

Fix two issues discovered by Coverity:

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

CID: 1369623
CID: 1019001

Do you want me to resend or could you do that when committing?

Quoted 6 lines
Quoted 4 lines

Thanks,

Juergen

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#3 lore raw
Quoted 8 lines · Juergen Gross
Quoted 7 lines · Wei Liu
Quoted 1 line · Juergen Gross

Fix two issues discovered by coverity.

I would update the commit message to make it contain more information.

Fix two issues discovered by Coverity:

Quoted 8 lines
Quoted 5 lines

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

CID: 1369623
CID: 1019001

Do you want me to resend or could you do that when committing?

I can do it.

I will wait for Samuel's ack.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#4 lore raw
In reply to Wei Liu
Quoted 10 lines · Wei Liu, on Wed 17 Aug 2016 15:13:27 +0100, wrote:
Quoted 1 line · Juergen Gross

Fix two issues discovered by coverity.

I would update the commit message to make it contain more information.

Fix two issues discovered by Coverity:

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

Quoted 8 lines

CID: 1369623
CID: 1019001

Quoted 2 lines
Quoted 51 lines
Quoted 50 lines
---
 lib/printf.c | 25 +++++++++++--------------
 1 file changed, 11 insertions(+), 14 deletions(-)
lib/printf.c +11 -14
index ad6a304..f9e9d68 100644
@@ -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 {
Signature · 1 line
2.6.6
Signature · 7 lines
Samuel
"2 + 2 = 5 pour d'assez grandes valeurs de 2"

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel