Re: gcc: loop do not terminate

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]



> void testing(void)
> {
> #define NR_STRUCT_A   (4)
>       struct B*  ptr = malloc(sizeof(struct B) + NR_STRUCT_A*sizeof(struct
> A));
>
>       ptr->numelem = NR_STRUCT_A;
>       ptr->item    = (struct A*)(ptr+1);
>
>       ptr->item[0].a = 0;
>       ptr->item[1].a = 1;
>       ptr->item[2].a = 2;
>       ptr->item[3].a = 3;
>       ptr->item[4].a = 100;  /* Wrong, violate memory accessing here! */
> #undef  NR_STRUCT_A }

IMO, this is a viable alternative. The only disadvantage is that it is taking an extra sizeof(struct A *) bytes of memory, if memory space is a concern.


________________________________
CONFIDENTIALITY : This e-mail and any attachments are confidential and may be privileged. If you are not a named recipient, please notify the sender immediately and do not disclose the contents to another person, use it for any purpose or store or copy the information in any medium.


[Index of Archives]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [Share Photos]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Device Mapper]
  Powered by Linux