2

Clang 3.3 UBSan (未定義の動作サニタイザー) は、アライメントされていないアクセスの次のコードにフラグを立てました。

Address.cc:545:27: runtime error: load of misaligned address 0x60c00000a7df for type 'char *', which requires 8 byte alignment
0x60c00000a7df: note: pointer points here
 00 00 00 00 ef  a7 00 00 c0 60 00 00 00  00 00 00 00 00 00 00 c0  a8 64 0c 00 00 00 00 00  00 00 00
             ^
Address.cc:547:19: runtime error: reference binding to misaligned address 0x60c00000a7ef for type 'const struct in_addr', which requires 4 byte alignment
0x60c00000a7ef: note: pointer points here
 00 00 00 00 c0  a8 64 0c 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00
             ^

問題のコードを以下に示します ( の誤った戻り値の型は無視してoperator=ください)。

bool
Ip::Address::operator =(const struct hostent &s)
{
    struct in_addr* ipv4 = NULL;

    switch (s.h_addrtype) {

    case AF_INET:
        // Line 545 below
        ipv4 = (in_addr*)(s.h_addr_list[0]);
        // Line 547 below
        operator=(*ipv4);
        break;
    ...
}

そしてhostent構造:

struct hostent {
  char    *h_name;        /* official name of host */
  char    **h_aliases;    /* alias list */
  int     h_addrtype;     /* host address type */
  int     h_length;       /* length of address */
  char    **h_addr_list;  /* list of addresses */
}

このスコークは Mac OS X システムで生成されます。これが Xcode または CFE Dev メーリング リストのバグであるという最近の議論を思い出します (ただし、現時点では見つけられません)。

編集: Sean McBride は親切にも電子メールへのリンクを提供してくれました: -fcatch-undefined-behavior false positive with readdir()? SIGBUS特にエラーが発生する可能性があるため、無視できるという声明には同意しません(アプリケーションではなくOSに由来するため) 。

Clangの問題を解決するためにポインターを再調整するにはどうすればよいですか(h_addr私に最も問題を引き起こしています)? それに依存しているAppleの内部構造のために、それを行うことさえできますか?

4

3 に答える 3

4

正しい値を保持するデータへのポインターを持っているが、オフセットが正しくない場合、memcpyそのデータが必要になる場合があります。あなたの場合、ipv4スタック変数(整列される)とmemcpytos.h_addr_list[0]に変わりますipv4

于 2013-09-16T07:03:35.887 に答える