summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Braun <rbraun@sceen.net>2017-06-25 13:32:13 +0200
committerRichard Braun <rbraun@sceen.net>2017-06-25 13:49:46 +0200
commit69a890f096aca015107c48bbfdfb27e53a932d24 (patch)
treebeb7e609b583a9385afa670d7eaec442cb977566
parentd471bf5cb67f8df526b769556800d7341c64560c (diff)
fmt: fix increment/decrement operator style mistakes
-rw-r--r--fmt.c51
1 files changed, 40 insertions, 11 deletions
diff --git a/fmt.c b/fmt.c
index ab4e28c..3f21bc1 100644
--- a/fmt.c
+++ b/fmt.c
@@ -524,7 +524,8 @@ fmt_sprintf_state_produce_int(struct fmt_sprintf_state *state)
if (n == 0) {
if (state->precision != 0) {
- tmp[i++] = '0';
+ tmp[i] = '0';
+ i++;
}
} else if (state->base == 10) {
/*
@@ -542,7 +543,8 @@ fmt_sprintf_state_produce_int(struct fmt_sprintf_state *state)
do {
r = n % 10;
n /= 10;
- tmp[i++] = fmt_digits[r];
+ tmp[i] = fmt_digits[r];
+ i++;
} while (n != 0);
#ifndef __LP64__
} else {
@@ -553,7 +555,8 @@ fmt_sprintf_state_produce_int(struct fmt_sprintf_state *state)
do {
r = m % 10;
m /= 10;
- tmp[i++] = fmt_digits[r];
+ tmp[i] = fmt_digits[r];
+ i++;
} while (m != 0);
}
#endif /* __LP64__ */
@@ -564,7 +567,8 @@ fmt_sprintf_state_produce_int(struct fmt_sprintf_state *state)
do {
r = n & mask;
n >>= shift;
- tmp[i++] = fmt_digits[r] | (state->flags & FMT_FORMAT_LOWER);
+ tmp[i] = fmt_digits[r] | (state->flags & FMT_FORMAT_LOWER);
+ i++;
} while (n != 0);
}
@@ -575,9 +579,12 @@ fmt_sprintf_state_produce_int(struct fmt_sprintf_state *state)
state->width -= state->precision;
if (!(state->flags & (FMT_FORMAT_LEFT_JUSTIFY | FMT_FORMAT_ZERO_PAD))) {
- while (state->width-- > 0) {
+ while (state->width > 0) {
+ state->width--;
fmt_sprintf_state_produce_raw_char(state, ' ');
}
+
+ state->width--;
}
if (state->flags & FMT_FORMAT_ALT_FORM) {
@@ -594,22 +601,32 @@ fmt_sprintf_state_produce_int(struct fmt_sprintf_state *state)
if (!(state->flags & FMT_FORMAT_LEFT_JUSTIFY)) {
c = (state->flags & FMT_FORMAT_ZERO_PAD) ? '0' : ' ';
- while (state->width-- > 0) {
+ while (state->width > 0) {
+ state->width--;
fmt_sprintf_state_produce_raw_char(state, c);
}
+
+ state->width--;
}
- while (i < state->precision--) {
+ while (i < state->precision) {
+ state->precision--;
fmt_sprintf_state_produce_raw_char(state, '0');
}
- while (i-- > 0) {
+ state->precision--;
+
+ while (i > 0) {
+ i--;
fmt_sprintf_state_produce_raw_char(state, tmp[i]);
}
- while (state->width-- > 0) {
+ while (state->width > 0) {
+ state->width--;
fmt_sprintf_state_produce_raw_char(state, ' ');
}
+
+ state->width--;
}
static void
@@ -620,14 +637,26 @@ fmt_sprintf_state_produce_char(struct fmt_sprintf_state *state)
c = va_arg(state->ap, int);
if (!(state->flags & FMT_FORMAT_LEFT_JUSTIFY)) {
- while (--state->width > 0) {
+ for (;;) {
+ state->width--;
+
+ if (state->width <= 0) {
+ break;
+ }
+
fmt_sprintf_state_produce_raw_char(state, ' ');
}
}
fmt_sprintf_state_produce_raw_char(state, c);
- while (--state->width > 0) {
+ for (;;) {
+ state->width--;
+
+ if (state->width <= 0) {
+ break;
+ }
+
fmt_sprintf_state_produce_raw_char(state, ' ');
}
}