473,395 Members | 1,649 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Borland C++ crazy Access violation error

I have a project in Borland C++ and few days ago a strange error started to appear. Everywhere I use std::strcmp, I get an exception "Access violation at address XXXXXXX. Write of address 0000000" during runtime. Usually I need to compare data retrieved from MySQL result using my SQL wrapper.
Example:
Expand|Select|Wrap|Line Numbers
  1. CMySQLResult * res = CConnection::GetSingletonPtr()->RunQuery(CSQLBuilder::GetSingletonPtr()->GetTemplate("objednavky/prijate/profily/nahlad"));
  2. for (int i=0;i<res->RowsCount();i++)
  3. {
  4.   TListItem * itm = list->Items->Add();
  5.   itm->Caption = (*res)[i][3];
  6.   itm->SubItems->Add(COMMAREPL((*res)[i][4],".",","));
  7.   itm->SubItems->Add(COMMAREPL((*res)[i][5],".",",")+AnsiString(std::strcmp((*res)[i][24],"1") == 0 ? " m" : " ks"));
  8.   // ...
  9. }
  10. delete res;
  11.  
I'm sure that (*res)[i][j] always returns valid value, even if the result doesn't contain such an index or it cointains NULL value, returned value will always be not-null. But strcmp always fails...

EDIT: When running another part of the code I got this exceptions: "Privileged instruction" or "Control has no parent", all raised when strcmp was called.
Jun 13 '11 #1
7 4813
weaknessforcats
9,208 Expert Mod 8TB
This code:

Expand|Select|Wrap|Line Numbers
  1. CMySQLResult * res = CConnection::GetSingletonPtr  etc...
says res is a pointer to a MySQLResult.

whereas this code:

Expand|Select|Wrap|Line Numbers
  1. itm->Caption = (*res)[i][3]; 
says that res is a pointer to and array element but I don't see the array declared. Therefore y are pointing to indeterminate memory. Tha is, memory that is not yours and therefore, your access violation. It does not appear strcmp is your culprit.
Jun 13 '11 #2
No, you got it wrong.
CMySQLResult contains operator [] which returns an array of data holders, and the second [] operator then returns actual value obtained from MySQL. The code I posted is working.

Please, read the description, when I say the error always comes from strcmp, it just comes from strcmp. And as I posted earlier, it is not just access violation, I would handle that kind of exception as I always do, but it raises other strange exception, again, only at the point when application calls strcmp.
Jun 13 '11 #3
weaknessforcats
9,208 Expert Mod 8TB
It's hard to know that CMySQLResult is a class. The posted code says it's a pointer. But that aside, you are saying then that
(*res)[i][24] is a const char* that always points to a valid C-string?

Expand|Select|Wrap|Line Numbers
  1. std::strcmp((*res)[i][24],"1") 
One thing I would do is follow this call using a debugger.
Jun 13 '11 #4
Yes, CMySQLResult is a class, (*res) dereferences the object.
And yes, it always points to a valid string (it's always char * string, no matter if the indexes are correct or not, at least it points to "\0" const string)

I would not post here if I knew the reason why is this happening. It never happened before. For example, I wrote this code:
Expand|Select|Wrap|Line Numbers
  1. if (std::strcmp("ab","ab") == 0)
  2.     ShowMessage("Equals");
  3.  
Even this results in an access violation error, is there anything wrong with these 2 lines of code?
Jun 13 '11 #5
weaknessforcats
9,208 Expert Mod 8TB
Your code compiles and executes OK using Visual Studio.NET 2008.

I just changed ShowMessage to cout.

So your error may be not in the code but in some project setting. Like CMySQLResult points to data that is not part of your process's address space. Maybe you have a multi-process program and are not sharing memory.

Have you been able to cout << (*res)[i][24]?
Jun 13 '11 #6
Unfortunately, I use Borland C++ for this project. As I mentioned, it started to happen only few days ago. CMySQLResult works with libmysql.dll, you may be right now but I don't quite understand why, it used to work as expected, why so sudden...
I think it has something to do with VCL.
I avoid using strcmp now, I just take the first parameter, cast it to AnsiString and directly compare to the second param and it works.
Jun 14 '11 #7
weaknessforcats
9,208 Expert Mod 8TB
Then you need to insert a srcmp call as an individual line that uses the same call arguments as the one in the code now. Then set a breakpoint and step in using your debugger.

The cout suggestion is a uickie debug but you should be using your debugger now.
Jun 14 '11 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Boogie El Aceitoso | last post by:
Hi, The code below produces an access violation error, complaining that an object is destroyed twice. I don't understand why this happens. Any help would be appreciated. ...
11
by: muser | last post by:
In the code I supplied before this one, the cause of the problem is an access violation error. When I run the debugger it skips into what I can only assume is the compilers version of my code. And...
0
by: AA | last post by:
This mail is regarding a trouble I'm facing with SQL Server 2000. I'm working with ASP .NET V 1.1 and SQL Server 2000. I have a reporting module that generates XML reports from the SQL Server 2000...
4
by: marvind | last post by:
I think I am running into the static initialization problem but I do not understand why. I am trying to parse a configuration file. To make this parser generic I register callbacks for various...
1
by: Oliver | last post by:
I have a database developed fully in Access 2000 which I make available to users of both Access 97 and Access 2000. I use a split front end/back end arrangement; with the BE in Access 97. When I...
4
by: =?Utf-8?B?dGhlamFzdml2?= | last post by:
Dear All, Here is my code: void main() { char *p="Hello"; *p='M'; //This is where the error occurs cout<<p<<endl; }
1
by: gnanapoongothai | last post by:
i have a program to calculate the CRC for a group of array values. SO i have program in a different file and i am passing the length and the array to the function and i am getting a access voilation...
2
by: jthep | last post by:
I'm trying to get this piece of code I converted from C to work in C++ but I'm getting an access violation error. Problem occurs at line 61. Someone can help me with this? The function...
2
by: gbasilveira | last post by:
Hello all. for all the tay long I have been having this problem and I have beed surfing all the web for help, but I can't find a solution. I am working on a project to open INI Files all the code...
3
by: bamsi | last post by:
Hi All, I have a typedef element defined inside the struct which i am trying to assign value using the memset and strcpy function.I am able to compile but while running it give me access...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.