[ wxwindows-Bugs-1572314 ] arrarys with
sizeof(T)<sizeof(base::base_type) on big-endian
SourceForge.net
noreply at sourceforge.net
Fri Oct 6 11:29:25 PDT 2006
Bugs item #1572314, was opened at 2006-10-06 20:29
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=109863&aid=1572314&group_id=9863
Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Common
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Oskar Linde (oskar_linde)
Assigned to: Nobody/Anonymous (nobody)
Summary: arrarys with sizeof(T)<sizeof(base::base_type) on big-endian
Initial Comment:
A bug in dynarray.h when making arrays storing types
smaller than base_type.
Example:
WX_DEFINE_ARRAY_SHORT(unsigned char, MyArr);
...
MyArr arr;
arr.Add(17);
assert(arr.Last() == 17); // Fails on big endian systems
while:
arr.SetCount(1);
arr[0] = 17;
assert(arr.Last() == 17); // Succeeds
The problem lies in Item() and operator[] referencing
the underlying array in a different way from what Add()
and Insert() does.
As far as I can see, the bug is there both with and
without wxUSE_STL, but I havn't verified.
A snippet from dynarray.h that shows the problem:
Here, T == char, and base_type == short
T& operator[](size_t uiIndex) const
{ return (T&)(base::operator[](uiIndex)); }
void Add(T lItem, size_t nInsert = 1)
{ base::Add((base_type)lItem, nInsert); }
In the first case, a (short &) is cast into a (char &)
(!)... In the second case, lItem argument is cast into
a (short) before being inserted in the underlying
short* array.
Those two behaviors give different results on big
endian systems. It is analogous to the following variants:
short *internal_data;
(1) *((char *)&internal_data[x]) = 17;
(2) internal_data[x] = (short) 17;
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=109863&aid=1572314&group_id=9863
More information about the wx-dev
mailing list