summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--arch/x86/machine/boot.c33
-rw-r--r--kern/fmt.c51
-rw-r--r--kern/string.c22
3 files changed, 76 insertions, 30 deletions
diff --git a/arch/x86/machine/boot.c b/arch/x86/machine/boot.c
index 63fcaf0a..76fbcb40 100644
--- a/arch/x86/machine/boot.c
+++ b/arch/x86/machine/boot.c
@@ -137,7 +137,9 @@ boot_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;
@@ -155,14 +157,18 @@ boot_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--;
}
}
@@ -187,15 +193,15 @@ boot_memset(void *s, int c, size_t n)
size_t __boot
boot_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);
}
void __boot
@@ -210,17 +216,22 @@ boot_panic(const char *msg)
s = boot_panic_intro_msg;
while ((ptr < end) && (*s != '\0')) {
- *ptr++ = (BOOT_CGACOLOR << 8) | *s++;
+ *ptr = (BOOT_CGACOLOR << 8) | *s;
+ ptr++;
+ s++;
}
s = msg;
while ((ptr < end) && (*s != '\0')) {
- *ptr++ = (BOOT_CGACOLOR << 8) | *s++;
+ *ptr = (BOOT_CGACOLOR << 8) | *s;
+ ptr++;
+ s++;
}
while (ptr < end) {
- *ptr++ = (BOOT_CGACOLOR << 8) | ' ';
+ *ptr = (BOOT_CGACOLOR << 8) | ' ';
+ ptr++;
}
cpu_halt();
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 */