This is the mail archive of the
ecos-discuss@sources.redhat.com
mailing list for the eCos project.
RE: bug in sprintf
- From: "Daniel Lidsten" <Daniel dot Lidsten at combitechsystems dot com>
- To: <ecos-discuss at sources dot redhat dot com>
- Cc: Knud Wöhler <woehler at ossi dot fho-emden dot de>
- Date: Mon, 2 Jun 2003 11:00:26 +0200
- Subject: RE: [ECOS] bug in sprintf
Hi,
I can see the same problem with printf and fprintf i.e. i cant print negative interger values. Is the below change a recomended fix (remove the line?)
Regards, Daniel Lidsten
> -----Original Message-----
> From: Knud Wöhler [mailto:woehler@ossi.fho-emden.de]
> Sent: den 30 maj 2003 17:34
> To: ecos-discuss@sources.redhat.com
> Subject: [ECOS] bug in sprintf
>
>
> Hi
>
> The sprintf() function can not handle negative integer
> values. I have tested
> it on the xscale plattform. The problem is in vfnprintf.cxx.
> The compiler
> (arm-elf-gcc 3.2) generates wrong code for line 2 (it removes
> the sign). If I
> remove line 1 the generated code is ok.
>
> #define SARG() \
> (flags&QUADINT ? va_arg(arg, cyg_int64) : \
> flags&LONGINT ? va_arg(arg, long) : \
> flags&SHORTINT ? (long)(short)va_arg(arg, int) : \
> flags&SIZET ? va_arg(arg, size_t) : \ <-- 1
> (long)va_arg(arg, int)) <-- 2
>
>
> with size_t:
> case 'd':
> case 'i':
> _uquad = SARG();
> 580: e3e03043 mvn r3, #67 ; 0x43
> 584: e24b0014 sub r0, fp, #20 ; 0x14
> 588: e0800003 add r0, r0, r3
> 58c: e50b01d0 str r0, [fp, -#464]
> 590: e51b303c ldr r3, [fp, -#60]
> 594: e2033020 and r3, r3, #32 ; 0x20
> 598: e3530000 cmp r3, #0 ; 0x0
> 59c: 0a00016e beq 5c0 <vfnprintf+0x5c0>
> // quadint
> 5a0: e51b3024 ldr r3, [fp, -#36]
> 5a4: e51b2024 ldr r2, [fp, -#36]
> 5a8: e2822008 add r2, r2, #8 ; 0x8
> 5ac: e50b2024 str r2, [fp, -#36]
> 5b0: e8930006 ldmia r3, {r1, r2}
> 5b4: e24b4e1d sub r4, fp, #464 ; 0x1d0
> 5b8: e9040006 stmdb r4, {r1, r2}
> 5bc: ea0001a1 b 68c <vfnprintf+0x68c>
> 5c0: e51b303c ldr r3, [fp, -#60]
> 5c4: e2033010 and r3, r3, #16 ; 0x10
> 5c8: e3530000 cmp r3, #0 ; 0x0
> 5cc: 0a00017c beq 5f8 <vfnprintf+0x5f8>
> // longint
> 5d0: e51b2024 ldr r2, [fp, -#36]
> 5d4: e51b3024 ldr r3, [fp, -#36]
> 5d8: e2833004 add r3, r3, #4 ; 0x4
> 5dc: e50b3024 str r3, [fp, -#36]
> 5e0: e5923000 ldr r3, [r2]
> 5e4: e1a00003 mov r0, r3
> 5e8: e3a01000 mov r1, #0 ; 0x0
> 5ec: e24b2e1d sub r2, fp, #464 ; 0x1d0
> 5f0: e9020003 stmdb r2, {r0, r1}
> 5f4: ea0001a1 b 68c <vfnprintf+0x68c>
> 5f8: e51b303c ldr r3, [fp, -#60]
> 5fc: e2033040 and r3, r3, #64 ; 0x40
> 600: e3530000 cmp r3, #0 ; 0x0
> 604: 0a00018a beq 630 <vfnprintf+0x630>
> // shortint
> 608: e51b2024 ldr r2, [fp, -#36]
> 60c: e51b3024 ldr r3, [fp, -#36]
> 610: e2833004 add r3, r3, #4 ; 0x4
> 614: e50b3024 str r3, [fp, -#36]
> 618: e1d230f0 ldrsh r3, [r2]
> 61c: e1a00003 mov r0, r3
> 620: e3a01000 mov r1, #0 ; 0x0
> 624: e24b2e1d sub r2, fp, #464 ; 0x1d0
> 628: e9020003 stmdb r2, {r0, r1}
> 62c: ea0001a1 b 68c <vfnprintf+0x68c>
> 630: e51b303c ldr r3, [fp, -#60]
> 634: e2033c02 and r3, r3, #512 ; 0x200
> 638: e3530000 cmp r3, #0 ; 0x0
> 63c: 0a000198 beq 668 <vfnprintf+0x668>
> // size_t
> 640: e51b2024 ldr r2, [fp, -#36]
> 644: e51b3024 ldr r3, [fp, -#36]
> 648: e2833004 add r3, r3, #4 ; 0x4
> 64c: e50b3024 str r3, [fp, -#36]
> 650: e5923000 ldr r3, [r2]
> 654: e1a00003 mov r0, r3
> 658: e3a01000 mov r1, #0 ; 0x0
> 65c: e24b2e1d sub r2, fp, #464 ; 0x1d0
> 660: e9020003 stmdb r2, {r0, r1}
> 664: ea0001a1 b 68c <vfnprintf+0x68c>
> // long
> 668: e51b2024 ldr r2, [fp, -#36]
> 66c: e51b3024 ldr r3, [fp, -#36]
> 670: e2833004 add r3, r3, #4 ; 0x4
> 674: e50b3024 str r3, [fp, -#36]
> 678: e5923000 ldr r3, [r2]
> 67c: e1a00003 mov r0, r3
> 680: e3a01000 mov r1, #0 ; 0x0
> <- cast to unsigned long long
> 684: e24b2e1d sub r2, fp, #464 ; 0x1d0
> 688: e9020003 stmdb r2, {r0, r1}
>
> 68c: e24b3e1d sub r3, fp, #464 ; 0x1d0
> 690: e9130018 ldmdb r3, {r3, r4}
> 694: e51b01d0 ldr r0, [fp, -#464]
> 698: e8800018 stmia r0, {r3, r4}
>
>
> size_t removed:
>
> case 'd':
> case 'i':
> _uquad = SARG();
> 580: e3e03043 mvn r3, #67 ; 0x43
> 584: e24b0014 sub r0, fp, #20 ; 0x14
> 588: e0800003 add r0, r0, r3
> 58c: e50b01d0 str r0, [fp, -#464]
> 590: e51b303c ldr r3, [fp, -#60]
> 594: e2033020 and r3, r3, #32 ; 0x20
> 598: e3530000 cmp r3, #0 ; 0x0
> 59c: 0a00016e beq 5c0 <vfnprintf+0x5c0>
> // quadint
> 5a0: e51b3024 ldr r3, [fp, -#36]
> 5a4: e51b2024 ldr r2, [fp, -#36]
> 5a8: e2822008 add r2, r2, #8 ; 0x8
> 5ac: e50b2024 str r2, [fp, -#36]
> 5b0: e8930006 ldmia r3, {r1, r2}
> 5b4: e24b4e1d sub r4, fp, #464 ; 0x1d0
> 5b8: e9040006 stmdb r4, {r1, r2}
> 5bc: ea000194 b 658 <vfnprintf+0x658>
>
> 5c0: e51b303c ldr r3, [fp, -#60]
> 5c4: e2033010 and r3, r3, #16 ; 0x10
> 5c8: e3530000 cmp r3, #0 ; 0x0
> 5cc: 0a00017c beq 5f8 <vfnprintf+0x5f8>
> // longint
> 5d0: e51b2024 ldr r2, [fp, -#36]
> 5d4: e51b3024 ldr r3, [fp, -#36]
> 5d8: e2833004 add r3, r3, #4 ; 0x4
> 5dc: e50b3024 str r3, [fp, -#36]
> 5e0: e5923000 ldr r3, [r2]
> 5e4: e1a00003 mov r0, r3
> 5e8: e1a01fc0 mov r1, r0, asr #31
> 5ec: e24b2e1d sub r2, fp, #464 ; 0x1d0
> 5f0: e9020003 stmdb r2, {r0, r1}
> 5f4: ea000194 b 658 <vfnprintf+0x658>
>
> 5f8: e51b303c ldr r3, [fp, -#60]
> 5fc: e2033040 and r3, r3, #64 ; 0x40
> 600: e3530000 cmp r3, #0 ; 0x0
> 604: 0a00018b beq 634 <vfnprintf+0x634>
> // shortint
> 608: e51b3024 ldr r3, [fp, -#36]
> 60c: e51b2024 ldr r2, [fp, -#36]
> 610: e2822004 add r2, r2, #4 ; 0x4
> 614: e50b2024 str r2, [fp, -#36]
> 618: e1d330f0 ldrsh r3, [r3]
> 61c: e50b31d8 str r3, [fp, -#472]
> 620: e51b31d8 ldr r3, [fp, -#472]
> 624: e1a04fc3 mov r4, r3, asr #31
> 628: e24b0e1d sub r0, fp, #464 ; 0x1d0
> 62c: e9000018 stmdb r0, {r3, r4}
> 630: ea000194 b 658 <vfnprintf+0x658>
> // long
> 634: e51b2024 ldr r2, [fp, -#36]
> 638: e51b3024 ldr r3, [fp, -#36]
> 63c: e2833004 add r3, r3, #4 ; 0x4
> 640: e50b3024 str r3, [fp, -#36]
> 644: e5923000 ldr r3, [r2]
> 648: e1a00003 mov r0, r3
> 64c: e1a01fc0 mov r1, r0, asr #31
> <-- cast to signed long long
> 650: e24b2e1d sub r2, fp, #464 ; 0x1d0
> 654: e9020003 stmdb r2, {r0, r1}
>
> 658: e24b3e1d sub r3, fp, #464 ; 0x1d0
> 65c: e9130018 ldmdb r3, {r3, r4}
> 660: e51b01d0 ldr r0, [fp, -#464]
> 664: e8800018 stmia r0, {r3, r4}
>
> I think because size_t is unsigned it should not be handled in SARG().
>
> Knud
>
>
> --
> Before posting, please read the FAQ:
> http://sources.redhat.com/fom/ecos
> and search the list
> archive: http://sources.redhat.com/ml/ecos-discuss
>
>
--
Before posting, please read the FAQ: http://sources.redhat.com/fom/ecos
and search the list archive: http://sources.redhat.com/ml/ecos-discuss