Jump to content

Recommended Posts

Hi, I have been experiencing corruption of private 'class' data.

I am using win2k, SourceBoost 6.70, with a 16F887 target.

 

It would appear that a "variable char array" or (pointer array using alloc)

delared as private class data, becomes over written.

 

I have included code to show the problem below. The commented out

sections are the alternative "pointer method" which produce the same symtoms.

 

The problem can be seen using the built-in debugger, although any 'watched' internal class

variables show 'error' but the 'CharBuff' variable in main shows the corrupt extracted data.

 

Any answers or "work-arounds" would be appreciated.

Regards... Tim

 

#include <system.h>


class Test
{
public:
void Test();

char mf_GetChar(int Index);  


private:


char m_Buff[3];	// Standard Method 

//	char* m_pBuff;	// Pointer Method 

};

void Test::Test(void)
{
// Standard Method 
m_Buff[0] = 'A';
m_Buff[1] = 'B';
m_Buff[2] = 'C';


/************ Pointer Method ************
m_pBuff = (char*) alloc(3);

if(m_pBuff != NULL)
{	
	m_pBuff[0] = 'A';
	m_pBuff[1] = 'B';
	m_pBuff[2] = 'C';
}
*/	

}


char Test::mf_GetChar(int Index)
{
return m_Buff[Index];	// Standard Method
//	return m_pBuff[Index];	// Pointer Method 
}




void main()
{
class Test T;
int Count = 0;

char CharBuff;

while(1)
{
	if(Count < 3)
	{
		CharBuff = T.mf_GetChar(Count);
		Count++;
	}
	else
	{
		Count = 0;
	}	

}
}

Link to post
Share on other sites

Thanks for reporting. This bug is now fixed and the fix will be available in the next release. Problem happens inside the constructor where array element are being initialized. A workaround is to initialize array elements outside of the constructor after class object declaration.

 

Regards,

Pavel

Link to post
Share on other sites

Hi Pavel,

 

Thanks for your quick reply.

I tried your advice but the problem still remains!!

 

I did wonder if we were working on the same "Build version",

and so download the program this morning, and yes it was a different version!!

 

I would like to make a suggestion that a Build number be added to the download page.

I realise this will increase site traffic, but there must also be people just downloading

every day, just "in case" there is a new build available!

 

 

Back to the problem:

 

I have added 2 C++ programs again to show the bug. (Both "without" Constructors)

 

One prog returns corrupt data, the other enters an infinite loop.

 

I also have to say that I am now relying on the built-in debugger

for my information, and not a "real world" application.

 

Best regards

Tim

 

#include <system.h>
#include <stdio.h>
#include <stdlib.h>


class Test1
{
public:
void Initialize(void);
char mf_GetChar(int Index);  
private:
char* m_pBuff;	
};


void Test1::Initialize(void)
{
m_pBuff = (char*) alloc(4);

if(m_pBuff != NULL)
{	
	m_pBuff[0] = 'A';
	m_pBuff[1] = 'B';
	m_pBuff[2] = 'C'; //****** This line puts the debugger in to an infinite loop !!
	m_pBuff[4] = 'D';

}
}


char Test1::mf_GetChar(int Index)
{
return m_pBuff[Index];	
}





void main()
{
class Test1 T;

T.Initialize();

int Count = 0;

char CharBuff;

while(1)
{
	if(Count < 3)
	{
		CharBuff = T.mf_GetChar(Count);
		Count++;
	}
	else
	{
		Count = 0;
	}	

}
}

 

 

#include <system.h>
#include <stdio.h>
#include <stdlib.h>


class Test2
{
public:
void Initialize(void);
char mf_GetChar(int Index);  
private:
char m_Buff[3];	
};



void Test2::Initialize(void)
{
m_Buff[0] = 'A';
m_Buff[1] = 'B'; // *** This variable is returned corrupt
m_Buff[2] = 'C';
}


char Test2::mf_GetChar(int Index)
{
return m_Buff[Index];	
}




void main(void)
{
class Test2 T;

T.Initialize();

int Count = 0;

char CharBuff;

while(1)
{
	if(Count < 3)
	{
		CharBuff = T.mf_GetChar(Count);
		Count++;
	}
	else
	{
		Count = 0;
	}	

}
}

Link to post
Share on other sites
...I did wonder if we were working on the same "Build version",

and so download the program this morning, and yes it was a different version!!

 

I would like to make a suggestion that a Build number be added to the download page.

I realise this will increase site traffic, but there must also be people just downloading

every day, just "in case" there is a new build available!

 

There is no need in build number as it does not change between versions and we releaseeach version only once.

 

 

Back to the problem:

 

I have added 2 C++ programs again to show the bug. (Both "without" Constructors)

 

One prog returns corrupt data, the other enters an infinite loop...

 

The workaround I ment was to initialize array outside of this class code like:

 

class Test T;
T.m_Buff[0] = 'A';
T.m_Buff[1] = 'B';
T.m_Buff[2] = 'C';

 

Regards,

Pavel

Link to post
Share on other sites

Hi Pavel,

 

I tried that and yes I can see the data in memory, and access it

outside the class, but the class members themselves, can't access it!

 

In fact the class members are accessing a completely

different section of memory, and will cause corruption

if used to try and change values of the variables.

 

***********

 

My mistake about build versions, I saw different modified

dates and assumed they were different. Obviously just a

feature of windows file system.

 

***************

 

Although I am a paid licence holder, If I were to pay for the

support option, would this allow me access to later build versions

such as a version with this class bug fixed??

 

Best Regards

Tim

Link to post
Share on other sites
Although I am a paid licence holder, If I were to pay for the

support option, would this allow me access to later build versions

such as a version with this class bug fixed??

 

Not now. This is an interesting idea which we haven't thought about. Maybe we should adopt it.

 

Currently we supply beta builds to a small number of our customers (usually these are several very active compiler users) before public release. This time things are a bit different because in the coming release we plan to release BooctC++ commercially and it will use it's own protection mechanism (while now it uses same protection as BoostC). Because of these protection complications we probably will not release a beta to anybody this time.

 

Regards,

Pavel

Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...