At Mon, 19 Mar 2012 15:18:28 +0100, qbert biker wrote:
> > That's correct, although the patch you've linked to may not work
> > correctly for 64-bit systems. A better fix would be to change the
> > argument type of getTiFileBytes from size_t * to uint32_t *.
> 
> I'm very late but I just discovered this discussion. 
> The patch was created to support 64 Bit and works fine with
> my 64 Bit machines. If a 32-Bit system is used, the patch 
> may be unnecessary. 

Hi Hubert,

The reason for my comment above was that on amd64, size_t is a 64-bit
type. So, if you cast segment.size (which is of type uint32_t) instead
of changing the argument type, you end up with getTiFileBytes writing
8 bytes to a memory location for which only 4 bytes are guaranteed to
be allocated.

You're correct that this does appear to work, but this is due to the
fact that (a) amd64 is little-endian, so the lower 32 bits end up in
the right place anyway, and (b) segment.size is located at the very
end of the object, which is heap-allocated and probably contains a bit
of unused padding which can be trashed without consequence.

This fix may not work if the class layout is altered. What I'd suggest
is something like the following:

---
 DLL430_v3/src/TI/DLL430/FileFuncImpl.cpp |    2 +-
 DLL430_v3/src/TI/DLL430/FileFuncImpl.h   |    2 +-
 DLL430_v3/src/TI/DLL430/HalResponse.h    |    1 +
 3 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/DLL430_v3/src/TI/DLL430/FileFuncImpl.cpp 
b/DLL430_v3/src/TI/DLL430/FileFuncImpl.cpp
index 95877ab..79e3cb1 100644
--- a/DLL430_v3/src/TI/DLL430/FileFuncImpl.cpp
+++ b/DLL430_v3/src/TI/DLL430/FileFuncImpl.cpp
@@ -199,7 +199,7 @@ bool FileFuncImpl::getTiFileAddress(const string& record, 
uint32_t * address)
 //            WORD* ByteCnt (receives the number of values stored)
 // Result:    bool (true if line is ok, otherwise false)
 
-bool FileFuncImpl::getTiFileBytes(const string& Record, size_t* ByteCnt)
+bool FileFuncImpl::getTiFileBytes(const string& Record, uint32_t* ByteCnt)
 {
        stringstream stream(Record);
        int numBytes = 0;
diff --git a/DLL430_v3/src/TI/DLL430/FileFuncImpl.h 
b/DLL430_v3/src/TI/DLL430/FileFuncImpl.h
index 4819c1b..466879b 100644
--- a/DLL430_v3/src/TI/DLL430/FileFuncImpl.h
+++ b/DLL430_v3/src/TI/DLL430/FileFuncImpl.h
@@ -185,7 +185,7 @@ namespace TI
 
                        void trimWhitespace(string& str);
                        bool getTiFileAddress(const string& record, uint32_t* 
address);
-                       bool getTiFileBytes(const string& Record, size_t* 
ByteCnt);
+                       bool getTiFileBytes(const string& Record, uint32_t* 
ByteCnt);
 
                        bool gotoIntelRecordStart();
                        void readIntelData(istream& stream, uint8_t size, 
uint32_t address, bool firstData);
diff --git a/DLL430_v3/src/TI/DLL430/HalResponse.h 
b/DLL430_v3/src/TI/DLL430/HalResponse.h
index c4c19c9..c7f04ec 100644
--- a/DLL430_v3/src/TI/DLL430/HalResponse.h
+++ b/DLL430_v3/src/TI/DLL430/HalResponse.h
@@ -43,6 +43,7 @@
 
 #include <inttypes.h>
 #include <vector>
+#include <cstdio>
 
 namespace TI
 {

------------------------------------------------------------------------------
This SF email is sponsosred by:
Try Windows Azure free for 90 days Click Here 
http://p.sf.net/sfu/sfd2d-msazure
_______________________________________________
Mspgcc-users mailing list
Mspgcc-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mspgcc-users

Reply via email to