File: test_omniidl.cpp

package info (click to toggle)
tango 10.0.2%2Bdfsg1-2%2Bdeb13u1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 89,936 kB
  • sloc: cpp: 201,786; sh: 1,645; python: 953; java: 800; perl: 467; javascript: 447; xml: 325; makefile: 269; sql: 72; ruby: 24
file content (21 lines) | stat: -rw-r--r-- 869 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include "test_omniidl.h"
#include <iostream>

int main()
{
    // omniidl 4.2.1 has a bug in the c++ generation of IDL unions.
    // The union's copy constructor will not check the _pd__initialised flag
    // before accessing the other union to do the copy.
    //
    // Here we check for this by constructing a zeroed union and trying to copy
    // it.  The first member (with value 0) of the union is an IDL sequence so the
    // active member of the zeroed struct is a null pointer.  Therefore, this copy
    // will result in a segmentation fault.

    TestOmniidl::AttrValUnion zeroed;
    memset(static_cast<void *>(&zeroed), 0, sizeof(TestOmniidl::AttrValUnion));
    TestOmniidl::AttrValUnion copy{zeroed};

    // Print something so that the above is not optimized away.
    std::cout << "Active union memebr: " << static_cast<int>(copy._d()) << "\n";
}