On 11/12/10 07:57, Bruce Korb wrote: > On 11/11/10 18:51, Bruno Haible wrote: >>> Breakpoint 2, main (argc=2, argv=0x7fffffffdd38) >>> at ../../tests/test-fprintf-posix3.c:97 >>> 97 return 1; >>> (gdb) p repeat >>> $1 = 0 >>> (gdb) p errno >>> $2 = 12 >>> $ egrep ENOMEM $(find /usr/include -type f -name 'err*.h') >>> /usr/include/asm-generic/errno-base.h:#define ENOMEM 12 >>> >>> It returned ENOMEM on the first try. > > 92 d->dir = (DIRECTIVE *) malloc (d_allocated * sizeof (DIRECTIVE)); > (gdb) p d_allocated > $3 = 1 > (gdb) n > 93 if (d->dir == NULL) > (gdb) p *d > $4 = {count = 0, dir = 0x0, max_width_length = 140737488343584, > max_precision_length = 140737349717056} > (gdb) n > 95 goto out_of_memory_1; > > A "DIRECTIVE" is not very big:
Never mind. I misinterpreted what was going on. The problem lives in printf-parse.c. I modified the source thus: int PRINTF_PARSE (const CHAR_T *format, DIRECTIVES *d, arguments *a) { const CHAR_T *cp = format; /* pointer into format */ size_t arg_posn = 0; /* number of regular arguments consumed */ size_t d_allocated; /* allocated elements of d->dir */ size_t a_allocated; /* allocated elements of a->arg */ size_t max_width_length = 0; size_t max_precision_length = 0; d->count = 0; d_allocated = 1; a_allocated = d_allocated * sizeof (DIRECTIVE); d->dir = (DIRECTIVE *) malloc (a_allocated); and: (gdb) s printf_parse (format=0x405ac4 "%011000d\n", d=0x7fffffffd090, a=0x7fffffffd080) at ../../lib/printf-parse.c:83 83 const CHAR_T *cp = format; /* pointer into format */ (gdb) n 84 size_t arg_posn = 0; /* number of regular arguments consumed */ (gdb) 87 size_t max_width_length = 0; (gdb) 88 size_t max_precision_length = 0; (gdb) 90 d->count = 0; (gdb) 91 d_allocated = 1; (gdb) 92 a_allocated = d_allocated * sizeof (DIRECTIVE); (gdb) 93 d->dir = (DIRECTIVE *) malloc (a_allocated); (gdb) p a_allocated $1 = 0 (gdb) p d_allocated $2 = 1 Woops. We're allocating zero bytes. Preprocessed text: # 44 "../../lib/printf-parse.h" typedef struct { const char* dir_start; const char* dir_end; int flags; const char* width_start; const char* width_end; size_t width_arg_index; const char* precision_start; const char* precision_end; size_t precision_arg_index; char conversion; size_t arg_index; } char_directive; [...] # 80 "../../lib/printf-parse.c" int printf_parse (const char *format, char_directives *d, arguments *a) { const char *cp = format; size_t arg_posn = 0; size_t d_allocated; size_t a_allocated; size_t max_width_length = 0; size_t max_precision_length = 0; d->count = 0; d_allocated = 1; a_allocated = d_allocated * sizeof (char_directive); d->dir = (char_directive *) malloc (a_allocated); (gdb) x/24i printf_parse 0x4046b1 <printf_parse>: push %rbp 0x4046b2 <printf_parse+1>: mov %rsp,%rbp 0x4046b5 <printf_parse+4>: push %rbx 0x4046b6 <printf_parse+5>: sub $0x118,%rsp 0x4046bd <printf_parse+12>: mov %rdi,-0x108(%rbp) 0x4046c4 <printf_parse+19>: mov %rsi,-0x110(%rbp) 0x4046cb <printf_parse+26>: mov %rdx,-0x118(%rbp) 0x4046d2 <printf_parse+33>: mov -0x108(%rbp),%rax 0x4046d9 <printf_parse+40>: mov %rax,-0x18(%rbp) 0x4046dd <printf_parse+44>: movq $0x0,-0x20(%rbp) 0x4046e5 <printf_parse+52>: movq $0x0,-0x38(%rbp) 0x4046ed <printf_parse+60>: movq $0x0,-0x40(%rbp) 0x4046f5 <printf_parse+68>: mov -0x110(%rbp),%rax 0x4046fc <printf_parse+75>: movq $0x0,(%rax) 0x404703 <printf_parse+82>: movq $0x1,-0x28(%rbp) 0x40470b <printf_parse+90>: mov -0x28(%rbp),%rdx 0x40470f <printf_parse+94>: mov %rdx,%rax 0x404712 <printf_parse+97>: shl $0x2,%rax 0x404716 <printf_parse+101>: add %rdx,%rax 0x404719 <printf_parse+104>: add %rax,%rax 0x40471c <printf_parse+107>: add %rdx,%rax 0x40471f <printf_parse+110>: shl $0x3,%rax 0x404723 <printf_parse+114>: mov %rax,%rdi 0x404726 <printf_parse+117>: callq 0x400780 <mal...@plt> Breakpoint 1, printf_parse (format=0x405ac4 "%011000d\n", d=0x7fffffffd090, a=0x7fffffffd080) at ../../lib/printf-parse.c:83 83 const CHAR_T *cp = format; /* pointer into format */ (gdb) n 84 size_t arg_posn = 0; /* number of regular arguments consumed */ (gdb) 87 size_t max_width_length = 0; (gdb) 88 size_t max_precision_length = 0; (gdb) 90 d->count = 0; (gdb) 91 d_allocated = 1; (gdb) 92 a_allocated = d_allocated * sizeof (DIRECTIVE); (gdb) 93 d->dir = (DIRECTIVE *) malloc (a_allocated); (gdb) info registers rax 0x7fffffffd090 140737488343184 rbx 0x7fffffffd348 140737488343880 rcx 0x7ffff7979ed8 140737347296984 rdx 0x0 0 rsi 0x58 88 rdi 0x0 0 rbp 0x7fffffffcd70 0x7fffffffcd70 rsp 0x7fffffffcc50 0x7fffffffcc50 r8 0xffffffff 4294967295 r9 0x0 0 r10 0x22 34 r11 0x246 582 r12 0x400800 4196352 r13 0x7fffffffdd20 140737488346400 r14 0x0 0 r15 0x0 0 rip 0x404739 0x404739 <printf_parse+136> eflags 0x246 [ PF ZF IF ] cs 0x33 51 ss 0x2b 43 ds 0x0 0 es 0x0 0 fs 0x0 0 gs 0x0 0 (gdb) p a_allocated $6 = 0 I set "-O0", how much optimization happens? "rsi" is 88. I wonder why "rip" is at +133 when the call is at +117. $ gcc --version gcc (SUSE Linux) 4.5.0 20100604 [gcc-4_5-branch revision 160292] Copyright (C) 2010 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.