summaryrefslogtreecommitdiff
path: root/kern
diff options
context:
space:
mode:
authorRichard Braun <rbraun@sceen.net>2017-06-25 14:25:59 +0200
committerRichard Braun <rbraun@sceen.net>2017-06-25 14:25:59 +0200
commit66b03bcbc989cfcbd46dcbee1c9ab7ace54f98f0 (patch)
treecd1a815658b8a0cd07757937730515f6050394d0 /kern
parent308dae7cb2708e48699700556b0a49483097f262 (diff)
Fix increment/decrement operator style mistakes
Diffstat (limited to 'kern')
-rw-r--r--kern/fmt.c51
-rw-r--r--kern/string.c22
2 files changed, 54 insertions, 19 deletions
diff --git a/kern/fmt.c b/kern/fmt.c
index 34424e20..57ea0692 100644
--- a/kern/fmt.c
+++ b/kern/fmt.c
@@ -525,7 +525,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) {
/*
@@ -543,7 +544,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 {
@@ -554,7 +556,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__ */
@@ -565,7 +568,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);
}
@@ -576,9 +580,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) {
@@ -595,22 +602,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
@@ -621,14 +638,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, ' ');
}
}
diff --git a/kern/string.c b/kern/string.c
index 763012ae..7508e790 100644
--- a/kern/string.c
+++ b/kern/string.c
@@ -35,7 +35,9 @@ memcpy(void *dest, const void *src, size_t n)
src_ptr = src;
for (i = 0; i < n; i++) {
- *dest_ptr++ = *src_ptr++;
+ *dest_ptr = *src_ptr;
+ dest_ptr++;
+ src_ptr++;
}
return dest;
@@ -55,14 +57,18 @@ memmove(void *dest, const void *src, size_t n)
src_ptr = src;
for (i = 0; i < n; i++) {
- *dest_ptr++ = *src_ptr++;
+ *dest_ptr = *src_ptr;
+ dest_ptr++;
+ src_ptr++;
}
} else {
dest_ptr = dest + n - 1;
src_ptr = src + n - 1;
for (i = 0; i < n; i++) {
- *dest_ptr-- = *src_ptr--;
+ *dest_ptr = *src_ptr;
+ dest_ptr--;
+ src_ptr--;
}
}
@@ -110,15 +116,15 @@ memcmp(const void *s1, const void *s2, size_t n)
size_t
strlen(const char *s)
{
- size_t i;
+ const char *start;
- i = 0;
+ start = s;
- while (*s++ != '\0') {
- i++;
+ while (*s != '\0') {
+ s++;
}
- return i;
+ return (s - start);
}
#endif /* STRING_ARCH_STRLEN */