From: Suciu Flavius <suciuflavius@tiscali.de>
To: linux-c-programming@vger.kernel.org
Subject: Re: -EFAULT during freeing a pointer to a structure
Date: Fri, 08 Oct 2004 08:36:12 -0700 [thread overview]
Message-ID: <ck5bs3$uis$1@sea.gmane.org> (raw)
In-Reply-To: <OFA6DAB128.ACBA7070-ONC1256F24.0054FB89@bln.d-trust.de>
Hi,
your problem is with the vector limit:
struct abc mystruct[7];
mystruct[7].bla = "bla bla bla" IS SEGMENTATION FAULT !!!!!
the valid range is 0 - 6, so the last one is mystruct[6].bla = "bla";
The multiply by 4 is another stuff, the 32 bits and more processors
loves to read from 4n addresses, that's why compilers generate structs
with sizeof == 4n
But, anyway, your problem here is the vector limit, read the manual ;)
p.boehm@d-trust.net wrote:
> hi,
> I've found the error. the problem occurs if MAXNUM or number of array to store pointers of another
> structure is odd.
> I know that malloc() always allocates memory as multiple of 4 but in my case it is so:
>
> struct xy {
> int id; /* sizeof(int)=4 */
> char *name; /* sizeof(char *)=4 */
> };
>
> struct abc {
> struct xy *next[7]; /* sizeof(struct xy *) * 7 = 4 * 7 = 28 */
> };
>
> => all in all 36 bytes, and that's even!
>
> Can someone explain this? (I fears the solution is more than easy ...)
> pb
>
> -
> To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
next prev parent reply other threads:[~2004-10-08 15:36 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-10-05 15:43 -EFAULT during freeing a pointer to a structure p.boehm
2004-10-08 15:36 ` Suciu Flavius [this message]
-- strict thread matches above, loose matches on Subject: below --
2004-10-05 11:19 p.boehm
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='ck5bs3$uis$1@sea.gmane.org' \
--to=suciuflavius@tiscali.de \
--cc=linux-c-programming@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).