Skip to contentSkip to conversation

common/vsprintf: Fix signed->unsigned error, causing glacial performance.

PATCH In review Andrew Cooper 2 participants 4 messages Nov 12, 2013 – Nov 13, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 common/vsprintf: Fix signed->unsigned error, causing glacial performance.

The original patch for

c/s 67a3542c5bc356e6452d8305991617c875f87de4 "common/vsprintf: Refactor string() out of vsnprintf()"

specifically used signed integers, identical to the code copied out of vsprintf.

When committed, these had changed to unsigned integers, which causes a functional change. This causes glacial boot performance and an excessive quantity of spaces printed to the serial console, as we loop to the upper bound of a 32bit integer.

CC Keir Fraser <[email protected]>
CC Jan Beulich <[email protected]>
---
 xen/common/vsprintf.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
xen/common/vsprintf.c +1 -1
index e8f45eb..43dc392 100644
@@ -239,7 +239,7 @@ static char *number(
 static char *string(char *str, char *end, const char *s,
                     int field_width, int precision, int flags)
 {
-    unsigned int i, len = strnlen(s, precision);
+    int i, len = strnlen(s, precision);
 
     if (!(flags & LEFT)) {
         while (len < field_width--) {
Signature · 1 line
1.7.10.4
#1 lore raw
Quoted 9 lines
Quoted 1 line
Quoted 1 line · Andrew Cooper

The original patch for

c/s 67a3542c5bc356e6452d8305991617c875f87de4 "common/vsprintf: Refactor string() out of vsnprintf()"

specifically used signed integers, identical to the code copied out of vsprintf.

Quoted 6 lines

When committed, these had changed to unsigned integers, which causes a functional change. This causes glacial boot performance and an excessive quantity of spaces printed to the serial console, as we loop to the upper bound of a 32bit integer.

Considering that I had changed those on the fly while committing, I committed this one without waiting for an ack. But ...

xen/common/vsprintf.c static char *number( · line 242

Quoted 8 lines
xen/common/vsprintf.c +1 -1
@@ -239,7 +239,7 @@ static char *number(
 static char *string(char *str, char *end, const char *s,
                     int field_width, int precision, int flags)
 {
-    unsigned int i, len = strnlen(s, precision);
+    int i, len = strnlen(s, precision);

... this just looks _so_ wrong (and whenever I'll come across this again, I'll just be tempted again to adjust it)!

Jan

#2 lore raw
Quoted 29 lines · Jan Beulich
Quoted 9 lines
Quoted 1 line
Quoted 1 line · Andrew Cooper

The original patch for

c/s 67a3542c5bc356e6452d8305991617c875f87de4 "common/vsprintf: Refactor string() out of vsnprintf()"

specifically used signed integers, identical to the code copied out of vsprintf.

Quoted 6 lines

When committed, these had changed to unsigned integers, which causes a functional change. This causes glacial boot performance and an excessive quantity of spaces printed to the serial console, as we loop to the upper bound of a 32bit integer.

Considering that I had changed those on the fly while committing, I committed this one without waiting for an ack. But ...

xen/common/vsprintf.c static char *number( · line 242

Quoted 8 lines
xen/common/vsprintf.c +1 -1
@@ -239,7 +239,7 @@ static char *number(
 static char *string(char *str, char *end, const char *s,
                     int field_width, int precision, int flags)
 {
-    unsigned int i, len = strnlen(s, precision);
+    int i, len = strnlen(s, precision);

... this just looks _so_ wrong (and whenever I'll come across this again, I'll just be tempted again to adjust it)!

Quoted 2 lines

Jan

I agree in general, and do err on the side of unsigned whenever possible. In this case, I went with exactly what was present before.

~Andrew

#3 lore raw
Quoted 14 lines
Quoted 1 line
Quoted 1 line · Andrew Cooper
Quoted 11 lines · Jan Beulich

xen/common/vsprintf.c static char *number( · line 242

Quoted 9 lines
Quoted 1 line
Quoted 1 line · Andrew Cooper
xen/common/vsprintf.c +1 -1
@@ -239,7 +239,7 @@ static char *number(
 static char *string(char *str, char *end, const char *s,
                     int field_width, int precision, int flags)
 {
-    unsigned int i, len = strnlen(s, precision);
+    int i, len = strnlen(s, precision);

... this just looks _so_ wrong (and whenever I'll come across this again, I'll just be tempted again to adjust it)!

Quoted 2 lines

I agree in general, and do err on the side of unsigned whenever possible. In this case, I went with exactly what was present before.

And after having committed your fixup, I realized that I should have made them explicitly "signed" (and going forward we should try to do so elsewhere when signedness really matters).

Jan