From mboxrd@z Thu Jan 1 00:00:00 1970 From: apwingo@eos.ncsu.edu To: gcc-gnats@gcc.gnu.org Subject: c/3440: pointer to a struct changes when no assignment has been made to it Date: Wed, 27 Jun 2001 08:26:00 -0000 Message-id: <20010627151904.32184.qmail@sourceware.cygnus.com> X-SW-Source: 2001-06/msg01124.html List-Id: >Number: 3440 >Category: c >Synopsis: pointer to a struct changes when no assignment has been made to it >Confidential: no >Severity: non-critical >Priority: medium >Responsible: unassigned >State: open >Class: wrong-code >Submitter-Id: net >Arrival-Date: Wed Jun 27 08:26:00 PDT 2001 >Closed-Date: >Last-Modified: >Originator: Andy Wingo >Release: gcc version 2.95.4 20010604 (Debian prerelease) >Organization: >Environment: Debian GNU/Linux unstable, updated last night (6/27) >Description: the 'd' pointer changes when the LADSPA_IS_PORT_INPUT macro is called. Here is the cpp'd code: static gboolean has_inp_out (const LADSPA_Descriptor *d, gint inp, gint out) { gint inp_count, out_count, i; inp_count = 0; out_count = 0; for (i=0; i < d->PortCount; i++) { if ((( d->PortDescriptors[i] ) & 0x1 ) && (( d->PortDescriptors[i] ) & 0x8 ) ) inp_count++; if ((( d->PortDescriptors[i] ) & 0x2 ) && (( d->PortDescriptors[i] ) & 0x8 ) ) out_count++; } if (inp_count==inp && out_count==out) return TRUE; else return FALSE; } Right in the first if, d changes to be equal to d->PortDescriptors. I've debugged this and it is repeatable. Here is the assembler that gets produced: Dump of assembler code for function has_inp_out: 0x80557ec : push %ebp 0x80557ed : mov %esp,%ebp 0x80557ef : sub $0xc,%esp 0x80557f2 : push %edi 0x80557f3 : push %esi 0x80557f4 : push %ebx 0x80557f5 : mov 0x8(%ebp),%edx 0x80557f8 : xor %esi,%esi 0x80557fa : xor %ebx,%ebx 0x80557fc : xor %ecx,%ecx 0x80557fe : mov 0x18(%edx),%eax 0x8055801 : cmp %eax,%ebx 0x8055803 : jae 0x805582f 0x8055805 : mov 0x1c(%edx),%edx 0x8055808 : mov %edx,0xfffffffc(%ebp) 0x805580b : mov %eax,%edi 0x805580d : lea 0x0(%esi),%esi 0x8055810 : mov 0xfffffffc(%ebp),%eax 0x8055813 : mov (%eax,%ecx,4),%edx 0x8055816 : mov %edx,%eax 0x8055818 : and $0x9,%eax 0x805581b : cmp $0x9,%eax 0x805581e : jne 0x8055821 0x8055820 : inc %esi 0x8055821 : and $0xa,%edx 0x8055824 : cmp $0xa,%edx 0x8055827 : jne 0x805582a 0x8055829 : inc %ebx 0x805582a : inc %ecx 0x805582b : cmp %edi,%ecx 0x805582d : jb 0x8055810 0x805582f : cmp 0xc(%ebp),%esi 0x8055832 : jne 0x8055840 0x8055834 : cmp 0x10(%ebp),%ebx 0x8055837 : jne 0x8055840 0x8055839 : mov $0x1,%eax 0x805583e : jmp 0x8055842 0x8055840 : xor %eax,%eax 0x8055842 : pop %ebx 0x8055843 : pop %esi 0x8055844 : pop %edi 0x8055845 : leave ---Type to continue, or q to quit--- 0x8055846 : ret End of assembler dump. >How-To-Repeat: >Fix: I'm no good with assembler. >Release-Note: >Audit-Trail: >Unformatted: