[ wxwindows-Bugs-1432568 ] wxDataInputStream::ReadDouble and Write
SourceForge.net
noreply at sourceforge.net
Mon Mar 3 21:55:20 PST 2008
Bugs item #1432568, was opened at 2006-02-16 03:18
Message generated for change (Comment added) made by axcn
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=109863&aid=1432568&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: Trivial
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: Cristiano (cavila)
Assigned to: Nobody/Anonymous (nobody)
Summary: wxDataInputStream::ReadDouble and Write
Initial Comment:
I'm using wxWidgets 2.6.2, wxMSW port compiled through
ming342 compiler. I use the dev-cpp editor often.
When I started using wxDataInputStream class found
errors on reading double data.
I checked the source code and found the following:
// Must be at global scope for VC++ 5
extern "C" void ConvertToIeeeExtended(double num,
unsigned char *bytes);
// Must be at global scope for VC++ 5
extern "C" double ConvertFromIeeeExtended(const
unsigned char *bytes);
double wxDataInputStream::ReadDouble()
{
#if wxUSE_APPLE_IEEE
char buf[10];
m_input->Read(buf, 10);
return ConvertFromIeeeExtended((unsigned char *)buf);
#else
return 0.0;
#endif
}
void wxDataOutputStream::WriteDouble(double d)
{
char buf[10];
#if wxUSE_APPLE_IEEE
ConvertToIeeeExtended(d, (unsigned char *)buf);
#else
#if !defined(__VMS__) && !defined(__GNUG__)
# pragma warning "wxDataOutputStream::WriteDouble() not
using IeeeExtended - will not work!"
#endif
buf[0] = '\0';
#endif
m_output->Write(buf, 10);
}
This is trying to read 10bytes of binary data from the
file as double. The double value for the compiler is 8
bytes long. I don't checked if wxUSE_APPLE_IEEE is
defined and the function is always returning 0.0 .
Making a check on file size before and after the read a
found a 10byte difference, so this symbol may be defined.
A possible solution is to define a compiler check for
sizeof(double) and read the write quantity of data from
file.
----------------------------------------------------------------------
Comment By: Dmitry Krayushkin (axcn)
Date: 2008-03-04 08:55
Message:
Logged In: YES
user_id=2026574
Originator: NO
Yes. I found this bug too.
This is my report of bug:
wxDataInputStraem::ReadDouble() not worked?
I test it under wxMSW (MinGW compiler) and wxGTK 2.8.9
See comments in code.
C++ code:
double test_double[2] = {0.0001, 0.0002};
wxUint64 test_uint64;
wxMemoryInputStream mem((char*)&test_double, 2 * sizeof(double));
wxDataInputStream data_stream(mem);
//bad read
//with ReadDouble() we get "0" and 10 byte offset with wxMSW and 0 byte
with wxGTK after 1 ReadDouble() read!
wxMessageDialog(NULL, wxString(wxT("Readed: "))<< data_stream.ReadDouble()
<< wxString(wxT("\nOffset after 1 ReadDouble() read: ")) <<
mem.TellI()).Show(true);
//now return to begin and try again with Read64()
//Read64() show "0.0001" with 8 byte offset. All right here.
mem.SeekI(0);
test_uint64 = data_stream.Read64();
wxMessageDialog(NULL, wxString(wxT("Readed with Read64(): ")) <<
*((double*)&test_uint64) << wxString(wxT("\nOffset after 1 Read64() read:
")) << mem.TellI()).Show(true);
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=109863&aid=1432568&group_id=9863
More information about the wx-dev
mailing list