VirtualBox

Changeset 6921 in vbox for trunk/include/VBox/com


Ignore:
Timestamp:
Feb 12, 2008 1:18:35 PM (17 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
28073
Message:

Main: COM Arrays: Allow for zero-sized arrays.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/VBox/com/array.h

    r6898 r6921  
    494494#if defined (VBOX_WITH_XPCOM)
    495495
    496         AssertReturn (aNewSize > 0, false);
    497 
    498         m.arr = (T *) nsMemory::Alloc (aNewSize * sizeof (T));
     496        /* Note: for zero-sized arrays, we use the size of 1 because whether
     497         * malloc(0) returns a null pointer or not (which is used in isNull())
     498         * is implementation-dependent according to the C standard. */
     499
     500        m.arr = (T *) nsMemory::Alloc (RT_MAX (aNewSize, 1) * sizeof (T));
    499501        AssertReturn (m.arr != NULL, false);
    500502
     
    505507
    506508#else
    507 
    508         AssertReturn (aNewSize > 0, false);
    509509
    510510        SAFEARRAYBOUND bound = { aNewSize, 0 };
     
    987987#if defined (VBOX_WITH_XPCOM)
    988988
    989         AssertReturn (aNewSize > 0, false);
    990 
    991         Base::m.arr = (I **) nsMemory::Alloc (aNewSize * sizeof (I *));
     989        /* Note: for zero-sized arrays, we use the size of 1 because whether
     990         * malloc(0) returns a null pointer or not (which is used in isNull())
     991         * is implementation-dependent according to the C standard. */
     992
     993        Base::m.arr = (I **) nsMemory::Alloc (RT_MAX (aNewSize, 1) * sizeof (I *));
    992994        AssertReturn (Base::m.arr != NULL, false);
    993995
     
    9981000
    9991001#else
    1000 
    1001         AssertReturn (aNewSize > 0, false);
    10021002
    10031003        SAFEARRAYBOUND bound = { aNewSize, 0 };
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette