Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Core » strcpy issue
strcpy issue [message #46726] Wed, 20 July 2016 17:44 Go to next message
forlano is currently offline  forlano
Messages: 1185
Registered: March 2006
Location: Italy
Senior Contributor
Hello,

the following code involving a silly STRCPY crash my application in release mode (upp 9994, 64 bit, gcc , c++11, lubuntu 16.04)

class Team : Moveable<Team> { 
public:
...
    char hstatus[50]; 
...
    Team();
    ~Team(){;}
};

......

sql.Execute("SELECT * FROM TEAMS order by N");
while(sql.Fetch()) {
   Team& t = VTeam.Add( (int)sql[N] );
    ...	
   strcpy (t.hstatus, (String) sql[HSTATUS] );   //<=== crash!
    ...	
}


instead works in debug mode.
On windows, 32 bit, old upp no c++11, it works too.
hstatus cannot be a String (I need to modify its content char by char when needed).

What is wrong in that innocent line?
Thanks,
Luigi
Re: strcpy issue [message #46728 is a reply to message #46726] Wed, 20 July 2016 22:28 Go to previous messageGo to next message
forlano is currently offline  forlano
Messages: 1185
Registered: March 2006
Location: Italy
Senior Contributor
forlano wrote on Wed, 20 July 2016 17:44

What is wrong in that innocent line?


Solved!
hstatus was shorter than the other string!
This bug remained silent so far.

Sorry for disturbing for this silly problem.
Luigi
Re: strcpy issue [message #46729 is a reply to message #46728] Thu, 21 July 2016 07:17 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Why do not you just use String?

Mirek
Re: strcpy issue [message #46737 is a reply to message #46729] Thu, 21 July 2016 12:54 Go to previous messageGo to next message
forlano is currently offline  forlano
Messages: 1185
Registered: March 2006
Location: Italy
Senior Contributor
mirek wrote on Thu, 21 July 2016 07:17
Why do not you just use String?

Mirek


Because the compiler complain when I try to change a single character inside the string, like

String s = "0000000000000000000000";
s[4] = '1';

Is there a way to do it?
Luigi
Re: strcpy issue [message #46738 is a reply to message #46737] Thu, 21 July 2016 13:37 Go to previous message
dolik.rce is currently offline  dolik.rce
Messages: 1789
Registered: August 2008
Location: Czech Republic
Ultimate Contributor

forlano wrote on Thu, 21 July 2016 12:54

String s = "0000000000000000000000";
s[4] = '1';

Is there a way to do it?

This should work:
String s = "0000000000000000000000";
s.Set(4, '1');


Honza
Previous Topic: Nightly packages compilation error
Next Topic: Vector(const Vector& v, int)
Goto Forum:
  


Current Time: Thu Apr 18 04:49:29 CEST 2024

Total time taken to generate the page: 0.02573 seconds