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.
This commit is contained in:
Christian Prochaska 2012-04-22 18:54:31 +02:00 committed by Norman Feske
parent 2f2fd33d96
commit 4c4d4e5c63
4 changed files with 59 additions and 2 deletions

32
base/run/printf.run Normal file
View File

@ -0,0 +1,32 @@
build "core init test/printf"
create_boot_directory
install_config {
<config>
<parent-provides>
<service name="ROM"/>
<service name="RAM"/>
<service name="CPU"/>
<service name="RM"/>
<service name="CAP"/>
<service name="PD"/>
<service name="SIGNAL"/>
<service name="LOG"/>
</parent-provides>
<default-route>
<any-service> <parent/> </any-service>
</default-route>
<start name="test-printf">
<resource name="RAM" quantum="10M"/>
</start>
</config>
}
build_boot_image "core init test-printf"
append qemu_args "-nographic -m 64"
run_genode_until {-1 = -1 = -1} 10
puts "Test succeeded"

View File

@ -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;
}
}

View File

@ -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 <base/printf.h>
int main(int argc, char **argv)
{
Genode::printf("-1 = %d = %ld\n", -1, -1L);
return 0;
}

View File

@ -0,0 +1,3 @@
TARGET = test-printf
SRC_CC = main.cc
LIBS = env