octave-bug-tracker
[Top][All Lists]
Advanced

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

[Octave-bug-tracker] [bug #51530] fsanitize=undefined errors


From: Rik
Subject: [Octave-bug-tracker] [bug #51530] fsanitize=undefined errors
Date: Mon, 24 Jul 2017 13:23:55 -0400 (EDT)
User-agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:54.0) Gecko/20100101 Firefox/54.0

Follow-up Comment #15, bug #51530 (project octave):

There is a problem with at least some of the code in mach-info.cc.


    static bool is_big_endian (void)
    {
      // Are we little or big endian?  From Harbison & Steele.

      union
      {
        long l;
        char c[sizeof (long)];
      } u;

      u.l = 1;

      return (u.c[sizeof (long) - 1] == 1);
    }


The code sets one member of a union, and then reads from another.  In C, this
behavior is guaranteed.  In C++, this is *not* guaranteed.  From
cppreference.com (http://en.cppreference.com/w/cpp/language/union):


The union is only as big as necessary to hold its largest data member. The
other data members are allocated in the same bytes as part of that largest
member. The details of that allocation are implementation-defined, and it's
undefined behavior to read from the member of the union that wasn't most
recently written. Many compilers implement, as a non-standard language
extension, the ability to read inactive members of a union. 


For a much longer article corroborating this, and where I got the idea for
using memcpy, see http://dbp-consulting.com/tutorials/StrictAliasing.html.




    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?51530>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]