call stack for no reason

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include <iostream>
#include <WinSock2.h>
#include <mysql.h>
#include <string>
#include <vector>
#include "action.h"
using namespace std;


MYSQL *con;
st_mysql_res* res = NULL;
MYSQL_FIELD  *	field[200];
MYSQL_ROW		myRow;

CAction * m_pActionList[1000];
int LoadActions();

int main()
{
	con = mysql_init(con);
	if(!mysql_real_connect(con,"127.0.0.1","test","test","account_zf",NULL,NULL,NULL))
	{
		cout<<"Error connected"<<endl;
		system("pause");
		exit(-1);
		return false;
	}
	LoadActions();
	system("pause");
	return 0;
}


int LoadActions()
{
	int iIndex = 0;
	int iRows;
	int iFields;
	MYSQL_ROW myRow;
	MYSQL_FIELD* field [200];

	for (int a = 0; a < 200; a++)
		field[a] = NULL;

	mysql_query(con, "SELECT * FROM `cq_action`;");
	res= mysql_store_result(con);
	if ((iRows = (int)mysql_num_rows(res)) > 0)
	{
		iFields = (WORD)mysql_num_fields(res);
		for(int b = 0; b < iRows; b++)
		{
			myRow = mysql_fetch_row(res);//Unhandled exception at 0x533e5e75 in tester.exe: 0xC0000005: Access violation reading location 0xcdcdcdd1.
			mysql_field_seek(res, 0);
			for(int f = 0; f < iFields; f++)
			{
				field[f] = mysql_fetch_field(res);
				if(field[f]) {
				if(!strcmp(field[f]->name, "id"))
				{
					iIndex++;
					m_pActionList[iIndex] = new class CAction;
					m_pActionList[iIndex]->id = atoi(myRow[f]);
					m_pActionList[iIndex]->index = iIndex;
				}
				else if(!strcmp(field[f]->name, "param"))
				{
					m_pActionList[iIndex]->param = new char[strlen(myRow[f])+1];
					m_pActionList[iIndex]->param[strlen(myRow[f])] = 0;
					memcpy(m_pActionList[iIndex]->param, myRow[f], strlen(myRow[f]));
				}
				else if(!strcmp(field[f]->name, "type"))
					m_pActionList[iIndex]->type = atoi(myRow[f]);
				else if(!strcmp(field[f]->name, "id_next"))
					m_pActionList[iIndex]->idnext = atoi(myRow[f]);
				else if(!strcmp(field[f]->name, "id_nextfail"))
					m_pActionList[iIndex]->idfail = atoi(myRow[f]);
				else if(!strcmp(field[f]->name, "data"))
					m_pActionList[iIndex]->data = atoi(myRow[f]);
				}
				else{
					if(field[f]=NULL)
						cout<<"error"<<endl;
				}
			}
		}
	}

	return 0;
}



idk why is this error happens
//Unhandled exception at 0x533e5e75 in tester.exe: 0xC0000005: Access violation reading location 0xcdcdcdd1.
It is common in the Microsoft runtime, when memory is allocated in a debug mode, to then write over that memory with the value 0xcdcdcdcd (i.e. before it is initialised with whatever value you intend to put in it). You are trying to access location 0xcdcdcdd1, which is so close to 0xcdcdcdcd that I'd guess that somewhere in your code you are trying to do something with memory that has been allocated but never actually had a value put into it; you would attempt to access location 0xcdcdcdd1 if you dereferenced a pointer holding that value, so the informed guess is that somewhere you have a bad pointer (possibly one that you are carrying out some arithmetic on before attempting to dereference it), or array.

If you run your code under a debugger, with debugging symbols in the build, it will tell you the exact line of code where this happens. You will save yourself vast amounts of time if you use a debugger.
Last edited on
Topic archived. No new replies allowed.