From 263f276afb0b78c5c8914a54975d383425869d66 Mon Sep 17 00:00:00 2001 From: Scott Wood Date: Tue, 14 Aug 2007 08:09:30 -0500 Subject: [PATCH 1/1] fixes/cleanup --- Makefile.head | 2 +- Makefile.target | 1 + kernel/io/console/misc.cc | 2 -- kernel/io/console/vga.cc | 2 -- lib/c++/orb.cc | 2 +- lib/c/freestanding/Makefile | 4 ++-- lib/c/freestanding/{sprintf.c => sprintf.cc} | 20 +++++++++++--------- 7 files changed, 16 insertions(+), 17 deletions(-) rename lib/c/freestanding/{sprintf.c => sprintf.cc} (96%) diff --git a/Makefile.head b/Makefile.head index da2bc1d..61456a0 100644 --- a/Makefile.head +++ b/Makefile.head @@ -51,7 +51,7 @@ OPT += -O2 DEBUG += -g3 ABI += -freg-struct-return -CXXFLAGS += $(CXXINCS) $(DEFS) $(CXXWARN) $(OPT) $(DEBUG) $(ABI) +CXXFLAGS += $(DEFS) $(CXXINCS) $(CXXWARN) $(OPT) $(DEBUG) $(ABI) BUILDCXXFLAGS += $(BUILDDEFS) $(CXXWARN) $(OPT) $(DEBUG) CFLAGS += $(CINCS) $(DEFS) $(CWARN) $(OPT) $(DEBUG) $(ABI) diff --git a/Makefile.target b/Makefile.target index 2943437..6da0ecf 100644 --- a/Makefile.target +++ b/Makefile.target @@ -85,6 +85,7 @@ STRIP := $(CROSS)strip DEFS += -D_LL_ARCH_$(ARCH) -D_LL_ARCH=$(ARCH) MKDIR := mkdir -p MV := mv +OBJCOPY := $(CROSS)objcopy RANLIB := $(CROSS)ranlib RM := rm -f RMDIR := rm -rf diff --git a/kernel/io/console/misc.cc b/kernel/io/console/misc.cc index 09f8623..7da0324 100644 --- a/kernel/io/console/misc.cc +++ b/kernel/io/console/misc.cc @@ -41,8 +41,6 @@ Lock::SpinLock printf_lock; // happens. If you really need that, you'll need to call snprintf // and primary_console->write yourself. -void vga_write(uint8_t *buf, u64 len); - size_t printf(const char *str, ...) { Lock::AutoSpinLockRecIRQ autolock(printf_lock); diff --git a/kernel/io/console/vga.cc b/kernel/io/console/vga.cc index d0c044e..7c52503 100644 --- a/kernel/io/console/vga.cc +++ b/kernel/io/console/vga.cc @@ -21,8 +21,6 @@ #include #include -void vga_write(char *str); - namespace IO { namespace Console { class VGA : public Console { diff --git a/lib/c++/orb.cc b/lib/c++/orb.cc index a62e91f..8533f52 100644 --- a/lib/c++/orb.cc +++ b/lib/c++/orb.cc @@ -57,7 +57,7 @@ namespace RunTime { }; typedef ::Util::RadixTree ObjTable; - ObjTable objtable; +// ObjTable objtable; unsigned long get_pc() { diff --git a/lib/c/freestanding/Makefile b/lib/c/freestanding/Makefile index 0257e46..27c18e8 100644 --- a/lib/c/freestanding/Makefile +++ b/lib/c/freestanding/Makefile @@ -1,10 +1,10 @@ DIR := c/freestanding/ DIRS += $(DIR) -RAW_CFILES := sprintf string +RAW_CFILES := string CFILES += $(RAW_CFILES:%=$(DIR)%) -RAW_CXXFILES := +RAW_CXXFILES := sprintf CXXFILES += $(RAW_CXXFILES:%=$(DIR)%) TARGETS += $(BUILDDIR)/c/libfreestanding.a diff --git a/lib/c/freestanding/sprintf.c b/lib/c/freestanding/sprintf.cc similarity index 96% rename from lib/c/freestanding/sprintf.c rename to lib/c/freestanding/sprintf.cc index a7aa115..acfbaff 100644 --- a/lib/c/freestanding/sprintf.c +++ b/lib/c/freestanding/sprintf.cc @@ -165,7 +165,7 @@ extern "C" size_t vsnprintf(char *buf, size_t size, break; } - if (opos < size) + if (opos < size - 1) buf[opos] = str[pos]; opos++; @@ -300,7 +300,7 @@ extern "C" size_t vsnprintf(char *buf, size_t size, arg = va_arg(args, int); flags |= num_signed; - printf_num(buf, opos, size, arg, 10, + printf_num(buf, opos, size - 1, arg, 10, fieldwidth, precision, flags); state = 0; break; @@ -340,14 +340,14 @@ extern "C" size_t vsnprintf(char *buf, size_t size, else arg = va_arg(args, unsigned int); - printf_num(buf, opos, size, arg, radix, + printf_num(buf, opos, size - 1, arg, radix, fieldwidth, precision, flags); state = 0; break; } case 'c': - if (opos < size) + if (opos < size - 1) buf[opos] = va_arg(args, int); opos++; @@ -361,7 +361,7 @@ extern "C" size_t vsnprintf(char *buf, size_t size, arg = "(null)"; size_t len = strlen(arg); - printf_string(buf, opos, size, arg, len); + printf_string(buf, opos, size - 1, arg, len); state = 0; break; } @@ -369,7 +369,7 @@ extern "C" size_t vsnprintf(char *buf, size_t size, case 'p': { const void *arg = va_arg(args, const void *); - printf_num(buf, opos, size, (unsigned long)arg, 16, + printf_num(buf, opos, size - 1, (unsigned long)arg, 16, fieldwidth, precision, flags); state = 0; @@ -398,7 +398,7 @@ extern "C" size_t vsnprintf(char *buf, size_t size, default_case: // label for goto default: - if (opos < size) + if (opos < size - 1) buf[opos] = str[pos]; opos++; @@ -406,8 +406,10 @@ extern "C" size_t vsnprintf(char *buf, size_t size, break; } } - - if (size > 0 && opos >= size) + + if (opos < size) + buf[opos] = 0; + else if (size > 0) buf[size - 1] = 0; return opos; -- 2.39.2