On Wed, Sep 26, 2012 at 12:56 PM, Sean McBride <span dir="ltr"><<a href="mailto:sean@rogue-research.com" target="_blank">sean@rogue-research.com</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Richard,<br>
<br>
It prints 8, for every iteration of the loop.  I guess that's correct since the first field of the struct is a uint64_t.</blockquote><div><br></div><div>What pointer values does it print? Are they 8 byte aligned?</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="HOEnZb"><font color="#888888">Sean<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
<br>
<br>
On Wed, 26 Sep 2012 12:49:38 -0700, Richard Smith said:<br>
<br>
>Can you try adding<br>
><br>
>  printf ("%p %zd\\n", d, _Alignof(*d));<br>
><br>
>before the line which fails? Is the pointer correctly aligned?<br>
><br>
>On Wed, Sep 26, 2012 at 12:38 PM, Sean McBride <<a href="mailto:sean@rogue-research.com">sean@rogue-research.com</a>>wrote:<br>
><br>
>> On Wed, 26 Sep 2012 10:40:47 -0400, Joe Ranieri said:<br>
>><br>
>> >> DIR* dir = opendir("/usr/lib");<br>
>> >> if (dir)<br>
>> >> {<br>
>> >>  struct dirent* d = NULL;<br>
>> >>  while ((d = readdir(dir)) != NULL)<br>
>> >>  {<br>
>> >>   const char* local = d->d_name; // bam!<br>
>> >>   printf ("%s\n", local);<br>
>> >>  }<br>
>> >>  closedir(dir);<br>
>> >> }<br>
>> >><br>
>> ><br>
>> > *SNIP*<br>
>> ><br>
>> >Just a hunch: is d->d_name an unaligned pointer? We ran into a similar<br>
>> >issue with gethostbyname.<br>
>><br>
>> Joe,<br>
>><br>
>> Thanks for your reply.  But I'm afraid I don't follow.  Unaligned with<br>
>> respect to what?  The 'struct dirent' is declared by the system basically<br>
>> like so:<br>
>><br>
>> #pragma pack()<br>
>> struct dirent {<br>
>>         uint64_t  d_ino;<br>
>>         uint64_t  d_seekoff;<br>
>>         uint16_t  d_reclen;<br>
>>         uint16_t  d_namlen;<br>
>>         uint8_t   d_type;<br>
>>         char      d_name[1024];<br>
>> }<br>
>><br>
>> Note the 'pragma pack'; is that the alignment you're referring to?  On my<br>
>> system, I don't see any pragma pack with gethostbyname()'s 'struct<br>
>> hostent', what problem did you have with it?<br>
>><br>
>> I just tried something else: it's not just the d_name field, but accessing<br>
>> any field triggers the SIGILL.<br>
<br>
<br>
</div></div></blockquote></div><br>