diff options
author | Danny Holman <dholman@gymli.xyz> | 2021-01-20 22:47:46 -0600 |
---|---|---|
committer | Danny Holman <dholman@gymli.xyz> | 2021-01-20 22:47:46 -0600 |
commit | fd4bd4dabe8011b016e3f8e6c3de5cfe6bc1f41d (patch) | |
tree | 95061887af560f1c46b0d6259ae20030da7af8fd | |
parent | 7e1bf77c0be04a34d8c4576f030ffc3ef973ac44 (diff) |
kernel: iterate over string with index
Iterate over a formatted string with an index and strlen instead of
using a non-const pointer. The latter method may result in unsafe memory
conditions.
Signed-off-by: Danny Holman <dholman@gymli.xyz>
-rw-r--r-- | kernel/io.c | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/kernel/io.c b/kernel/io.c index ca787b3..e2bef20 100644 --- a/kernel/io.c +++ b/kernel/io.c @@ -1,5 +1,6 @@ #include <kernel/io.h> #include <kernel/string.h> +#include <kernel/tty.h> char* convert(unsigned int num, int base) { static char rep[] = "0123456789ABCDEF"; @@ -18,19 +19,18 @@ char* convert(unsigned int num, int base) { } int vprintf(const char *fmt, va_list args) { - char *traverse; char *s; int i; - for (traverse = fmt; *traverse != '\0'; traverse++) { - if (*traverse != '%') { - tty_putchar(*traverse); + for (size_t n = 0; n < strlen(fmt); n++) { + if (fmt[n] != '%') { + tty_putchar(fmt[n]); continue; } else { - traverse++; + n++; } - switch (*traverse) { + switch (fmt[n]) { case 'c': i = va_arg(args, int); tty_putchar(i); |