From 941500d81138c22d96fc64f99c445c17352d437a Mon Sep 17 00:00:00 2001 From: maartenbrock Date: Fri, 26 Nov 2004 16:28:21 +0000 Subject: [PATCH] * device/lib/printf_large.c (_print_format): fixed bug 1073386, (calculate_digit): added optimization for octal and hex * support/regression/tests/bug1057979.c: added test for bug 1073386 git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@3586 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- ChangeLog | 15 ++++++--- device/lib/printf_large.c | 47 +++++++++++++++++++++++++++ support/regression/tests/bug1057979.c | 4 +++ 3 files changed, 62 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index a5e4fa2d..c608614c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,7 +1,14 @@ +2004-11-18 Maarten Brock + + * device/lib/printf_large.c (_print_format): fixed bug 1073386, + (calculate_digit): added optimization for octal and hex + * support/regression/tests/bug1057979.c: added test for bug 1073386 + 2004-11-25 Vangelis Rokas - * src/pic16/pcode.c: fixed bug which may produce error in non-GNU - compilers - + + * src/pic16/pcode.c: fixed bug which may produce error in non-GNU + compilers + 2004-11-25 Vangelis Rokas * src/pic16/device.h, @@ -25,7 +32,7 @@ Library is not automatically build yet. But one can build it by invoking 'make' inside the libc directory. * added ADC library under libio. Preliminary version yet. - + * src/pic16/gen.h: added emitTOGC macro, to toggle Carry flag, * src/pic16/gen.c (aopForRemat): asmop size is filled by aopForRemat() now and not by pic16_aopOp(), diff --git a/device/lib/printf_large.c b/device/lib/printf_large.c index cad0a047..1aa50e1e 100644 --- a/device/lib/printf_large.c +++ b/device/lib/printf_large.c @@ -141,6 +141,18 @@ static const char memory_id[] = "IXCP-"; #if defined ASM_ALLOWED static void calculate_digit( unsigned char radix ) { + if (radix == 8) + { + value.byte[4] = value.ul & 0x07; + value.ul >>= 3; + } + else if (radix == 16) + { + value.byte[4] = value.ul & 0x0F; + value.ul >>= 4; + } + else + { unsigned char i; for( i = 32; i != 0; i-- ) @@ -170,9 +182,22 @@ _endasm; } } } +} #elif defined SDCC_STACK_AUTO static void calculate_digit( value_t* value, unsigned char radix ) { + if (radix == 8) + { + value->byte[4] = value->ul & 0x07; + value->ul >>= 3; + } + else if (radix == 16) + { + value->byte[4] = value->ul & 0x0F; + value->ul >>= 4; + } + else + { unsigned char i; for( i = 32; i != 0; i-- ) @@ -187,9 +212,22 @@ static void calculate_digit( value_t* value, unsigned char radix ) } } } +} #else static void calculate_digit( unsigned char radix ) { + if (radix == 8) + { + value.byte[4] = value.ul & 0x07; + value.ul >>= 3; + } + else if (radix == 16) + { + value.byte[4] = value.ul & 0x0F; + value.ul >>= 4; + } + else + { unsigned char i; for( i = 32; i != 0; i-- ) @@ -204,6 +242,7 @@ static void calculate_digit( unsigned char radix ) } } } +} #endif #if USE_FLOATS @@ -648,6 +687,10 @@ get_conversion_spec: if (char_argument) { value.l = va_arg(ap,char); + if (!signed_argument) + { + value.l &= 0xFF; + } } else if (long_argument) { @@ -656,6 +699,10 @@ get_conversion_spec: else // must be int { value.l = va_arg(ap,int); + if (!signed_argument) + { + value.l &= 0xFFFF; + } } if ( signed_argument ) diff --git a/support/regression/tests/bug1057979.c b/support/regression/tests/bug1057979.c index 25877495..70d1e2c1 100644 --- a/support/regression/tests/bug1057979.c +++ b/support/regression/tests/bug1057979.c @@ -23,5 +23,9 @@ test_sprintf(void) sprintf( s, "%ld", 2147483647L ); ASSERT( 0 == strcmp( s, "2147483647" ) ); + //and from bug 1073386 + sprintf( s, "%04X", 0x8765u ); + ASSERT( 0 == strcmp( s, "8765" ) ); + ASSERT( s[12]==0x12 ); } -- 2.47.2