Please, help me to fix optimized value result in crash issue


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
Security sec;
	Security secl [100];
	SecurityList secList;
	while(!token.isEndOfInput()){
		if (token.isTransaction()){
			tran.action = token.getAction();
			tran.price = token.getPrice();
			tran.security = token.getSecurity();
			tran.share = token.getQuantity();
			tran.intTransactionDate = token.getYear()*10000
									+ token.getMonth()*100
									+ token.getDay();
			tran.transactionDate = to_string(tran.intTransactionDate);
			tranList.insert(tran);


			sec.security = token.getSecurity();
			int num = 0;
			for(int i = 0; i < 100; i++)
			{
				if(secl[i].security == sec.security){
					secl[i].tranList.insert(tran);
					break;
				}
				else if(secl[i].security != sec.security && i == 99){
					secl[num].security = sec.security;
					secl[num].tranList.insert(tran);
				}
			}
			++num;

			cout << "Tokenized transaction:" << endl;
			cout << "Transaction, Year: " << token.getYear();
			cout << ", Month: " << token.getMonth();
			cout << ", Day: " << token.getDay();
			cout << ", Action: " << token.getAction();
			cout << ", Security: " << token.getSecurity();
			cout << ", Number of Shares: " << token.getQuantity();
			cout << ", Price: " << token.getPrice() << endl;
		}
		token.nextLine();
	}

	for (int i = 0; i < 100; i++){
		secList.insert(secl[i]);
	}


void SecurityList::insert(Security sec){
	if (ssize < 100){
		slist[ssize] = sec; //'sec' BECOMES OPTIMIZED
		ssize++;
	}
}


when it's inserting the security object to security list, security value becomes optimized and terminates the program. any help would be appreciated.
Last edited on
What do you mean by "optimized"? What actually happens to sec?
I am a c++ newbie, so I don't even know what optimized actually means. it's just my debugger telling me the value is optimized. 'sec' holds a string and transaction list. but when it's trying to assign sec to securityList on line 51, sec values are not available.
Program received signal SIGSEGV, Segmentation fault.
0x00007fff88b1c222 in std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::~basic_string() () from /usr/lib/libc++.1.dylib

better debugging info
I am a c++ newbie, so I don't even know what optimized actually means. it's just my debugger telling me the value is optimized.

That's probably just the debugger telling you that it can't tell you what the values contained in sec are, because you're running an executable that was built with optimization on - commonly known as a "release" build. To get the full info you need for proper debugging, you'll want to build a "debug" build, with optimization switched off and debugging symbols included.

Consult your compiler/IDE documentation for details on how to do this.

Looking at your code, I notice that at lines 21 - 28, you're attempting to use a value from the secl array, but at that point you haven't initialized the array or assigned any values to it. This means that the value of secl[i] is undefined. This will almost certainly lead to bugs in your code.

This may well mean that the objects being passed into SecurityList::insert() are in an undefined state, causing the crash you're seeing.
Last edited on
thank you so much, initializing secl array with values did solve this issue.
You're welcome! Glad it worked out.
Topic archived. No new replies allowed.