From 4c4d4e5c639371ba988bea13f23829814148b7e2 Mon Sep 17 00:00:00 2001 From: Christian Prochaska Date: Sun, 22 Apr 2012 18:54:31 +0200 Subject: [PATCH] Fix printing of signed numbers If any operand of the '?' operator is of an unsigned type, the result is unsigned by default. Thanks to Julian Stecklina for finding this out. Fixes #189. --- base/run/printf.run | 32 ++++++++++++++++++++++++++++++++ base/src/base/console/console.cc | 4 ++-- base/src/test/printf/main.cc | 22 ++++++++++++++++++++++ base/src/test/printf/target.mk | 3 +++ 4 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 base/run/printf.run create mode 100644 base/src/test/printf/main.cc create mode 100644 base/src/test/printf/target.mk diff --git a/base/run/printf.run b/base/run/printf.run new file mode 100644 index 0000000000..b015bc494d --- /dev/null +++ b/base/run/printf.run @@ -0,0 +1,32 @@ +build "core init test/printf" + +create_boot_directory + +install_config { + + + + + + + + + + + + + + + + + + +} + +build_boot_image "core init test-printf" + +append qemu_args "-nographic -m 64" + +run_genode_until {-1 = -1 = -1} 10 + +puts "Test succeeded" diff --git a/base/src/base/console/console.cc b/base/src/base/console/console.cc index cd9313fb1f..9f050961d3 100644 --- a/base/src/base/console/console.cc +++ b/base/src/base/console/console.cc @@ -276,7 +276,7 @@ void Console::vprintf(const char *format, va_list list) case Format_command::LONG: numeric_arg = (cmd.type == Format_command::UINT) ? - va_arg(list, unsigned long) : va_arg(list, long); + (long long)va_arg(list, unsigned long) : va_arg(list, long); break; case Format_command::SIZE_T: @@ -287,7 +287,7 @@ void Console::vprintf(const char *format, va_list list) case Format_command::DEFAULT: numeric_arg = (cmd.type == Format_command::UINT) ? - va_arg(list, unsigned int) : va_arg(list, int); + (long long)va_arg(list, unsigned int) : va_arg(list, int); break; } } diff --git a/base/src/test/printf/main.cc b/base/src/test/printf/main.cc new file mode 100644 index 0000000000..e0eb1e0201 --- /dev/null +++ b/base/src/test/printf/main.cc @@ -0,0 +1,22 @@ +/* + * \brief Testing 'printf()' with negative integer + * \author Christian Prochaska + * \date 2012-04-20 + * + */ + +/* + * Copyright (C) 2012 Genode Labs GmbH + * + * This file is part of the Genode OS framework, which is distributed + * under the terms of the GNU General Public License version 2. + */ + +#include + +int main(int argc, char **argv) +{ + Genode::printf("-1 = %d = %ld\n", -1, -1L); + + return 0; +} diff --git a/base/src/test/printf/target.mk b/base/src/test/printf/target.mk new file mode 100644 index 0000000000..3bcfb4eb36 --- /dev/null +++ b/base/src/test/printf/target.mk @@ -0,0 +1,3 @@ +TARGET = test-printf +SRC_CC = main.cc +LIBS = env