mardi 20 avril 2021

Map memory data garbled in C++

I define a global map map<string, int> sourceMap to record the mapping between the line number and the source line. There are problems:

1)When I iterate the map if I print the src first and the number second, the print is garbled. However, the reverse is normal.

Garbled outputs and codes:

**codes:**
for (auto item = sourceMap.begin(); item != sourceMap.end(); item++) {
                cout << "line: " << item->first<< ", line2number:"<<sourceMap[item->first]<<endl;
            }


**outputs:**
, line2number:8dminInterface
, line2number:30payable{}
, line2number:14minInterface(){
, line2number:24t(addressdataBase)payableonlyOwner
, line2number:36dOwner(addressnewAddr)payable
, line2number:32ansfer(addressmultisig)payableonlyOwner{
line: msg.value>Limit, line2number:38
, line2number:33ransfer(msg.value);
, line2number:44ansfer(this.balance);
, line2number:41egatecall(bytes4(keccak256("AddToWangDB(address)")),msg.sender);

Normal outputs and codes of the reverse:

**code:**
 for (auto item = sourceMap.begin(); item != sourceMap.end(); item++) {
      cout << "line2number:"<<sourceMap[item->first] << ",line: " << item->first <<endl;
}

**outputs:**
line2number:32,line: functiontransfer(addressmultisig)payableonlyOwner{
line2number:38,line: msg.value>Limit
line2number:33,line: multisig.transfer(msg.value);
line2number:44,line: newAddr.transfer(this.balance);
line2number:41,line: oracle.delegatecall(bytes4(keccak256("AddToWangDB(address)")),msg.sender);
line2number:27,line: oracle=dataBase;
line2number:7,line: pragmasolidity^0.4.18;
line2number:19,line: require(msg.sender==Owner);
line2number:12,line: uint256publicLimit;
line2number:39,line: {

2) The map cannot find the corresponding value of many keys.

the abnormal outputs: ''' number: 0, new_line: oracle.delegatecall(bytes4(keccak256("AddToWangDB(address)")),msg.sender); '''

and the normal outputs: ''' number: 38, new_line: msg.value>Limit '''

A phrase of the corresponding codes:

 while (getline(blockText, lllline)){
       remove_escapesALL(lllline);
       cout<<"number: "<<sourceMap[lllline]<<", new_line: "<<lllline<<endl;
}

Aucun commentaire:

Enregistrer un commentaire