Skip to content

Commit eadde1e

Browse files
committedJul 6, 2014
Fix errors/warnings reported by valgrind
1 parent 6bd1524 commit eadde1e

File tree

4 files changed

+32
-32
lines changed

4 files changed

+32
-32
lines changed
 

‎src/connection.cpp

+21-21
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ std::list<SharedBuffer<u8> > makeSplitPacket(
125125
{
126126
// Chunk packets, containing the TYPE_SPLIT header
127127
std::list<SharedBuffer<u8> > chunks;
128-
128+
129129
u32 chunk_header_size = 7;
130130
u32 maximum_data_size = chunksize_max - chunk_header_size;
131131
u32 start = 0;
@@ -136,12 +136,12 @@ std::list<SharedBuffer<u8> > makeSplitPacket(
136136
end = start + maximum_data_size - 1;
137137
if(end > data.getSize() - 1)
138138
end = data.getSize() - 1;
139-
139+
140140
u32 payload_size = end - start + 1;
141141
u32 packet_size = chunk_header_size + payload_size;
142142

143143
SharedBuffer<u8> chunk(packet_size);
144-
144+
145145
writeU8(&chunk[0], TYPE_SPLIT);
146146
writeU16(&chunk[1], seqnum);
147147
// [3] u16 chunk_count is written at next stage
@@ -150,7 +150,7 @@ std::list<SharedBuffer<u8> > makeSplitPacket(
150150

151151
chunks.push_back(chunk);
152152
chunk_count++;
153-
153+
154154
start = end + 1;
155155
chunk_num++;
156156
}
@@ -465,9 +465,9 @@ SharedBuffer<u8> IncomingSplitBuffer::insert(BufferedPacket &p, bool reliable)
465465
sp->reliable = reliable;
466466
m_buf[seqnum] = sp;
467467
}
468-
468+
469469
IncomingSplitPacket *sp = m_buf[seqnum];
470-
470+
471471
// TODO: These errors should be thrown or something? Dunno.
472472
if(chunk_count != sp->chunk_count)
473473
LOG(derr_con<<"Connection: WARNING: chunk_count="<<chunk_count
@@ -483,15 +483,15 @@ SharedBuffer<u8> IncomingSplitBuffer::insert(BufferedPacket &p, bool reliable)
483483
// lag and the server re-sends stuff.
484484
if(sp->chunks.find(chunk_num) != sp->chunks.end())
485485
return SharedBuffer<u8>();
486-
486+
487487
// Cut chunk data out of packet
488488
u32 chunkdatasize = p.data.getSize() - headersize;
489489
SharedBuffer<u8> chunkdata(chunkdatasize);
490490
memcpy(*chunkdata, &(p.data[headersize]), chunkdatasize);
491-
491+
492492
// Set chunk data in buffer
493493
sp->chunks[chunk_num] = chunkdata;
494-
494+
495495
// If not all chunks are received, return empty buffer
496496
if(sp->allReceived() == false)
497497
return SharedBuffer<u8>();
@@ -503,7 +503,7 @@ SharedBuffer<u8> IncomingSplitBuffer::insert(BufferedPacket &p, bool reliable)
503503
{
504504
totalsize += i->second.getSize();
505505
}
506-
506+
507507
SharedBuffer<u8> fulldata(totalsize);
508508

509509
// Copy chunks to data buffer
@@ -561,6 +561,7 @@ Channel::Channel() :
561561
next_outgoing_split_seqnum(SEQNUM_INITIAL),
562562
current_packet_loss(0),
563563
current_packet_too_late(0),
564+
current_packet_successfull(0),
564565
packet_loss_counter(0),
565566
current_bytes_transfered(0),
566567
current_bytes_received(0),
@@ -2096,7 +2097,7 @@ void ConnectionReceiveThread::receive()
20962097
// infrastructure
20972098
unsigned int packet_maxsize = 1500;
20982099
SharedBuffer<u8> packetdata(packet_maxsize);
2099-
2100+
21002101
bool packet_queued = true;
21012102

21022103
unsigned int loop_count = 0;
@@ -2146,13 +2147,13 @@ void ConnectionReceiveThread::receive()
21462147

21472148
u16 peer_id = readPeerId(*packetdata);
21482149
u8 channelnum = readChannel(*packetdata);
2149-
2150+
21502151
if(channelnum > CHANNEL_COUNT-1){
21512152
LOG(derr_con<<m_connection->getDesc()
21522153
<<"Receive(): Invalid channel "<<channelnum<<std::endl);
21532154
throw InvalidIncomingDataException("Channel doesn't exist");
21542155
}
2155-
2156+
21562157
/* preserve original peer_id for later usage */
21572158
u16 packet_peer_id = peer_id;
21582159

@@ -2202,7 +2203,7 @@ void ConnectionReceiveThread::receive()
22022203
}
22032204
}
22042205

2205-
2206+
22062207
/* mark peer as seen with id */
22072208
if (!(packet_peer_id == PEER_ID_INEXISTENT))
22082209
peer->setSentWithID();
@@ -2215,7 +2216,7 @@ void ConnectionReceiveThread::receive()
22152216
{
22162217
channel = &(dynamic_cast<UDPPeer*>(&peer)->channels[channelnum]);
22172218
}
2218-
2219+
22192220
if (channel != 0) {
22202221
channel->UpdateBytesReceived(received_size);
22212222
}
@@ -2226,17 +2227,17 @@ void ConnectionReceiveThread::receive()
22262227
SharedBuffer<u8> strippeddata(received_size - BASE_HEADER_SIZE);
22272228
memcpy(*strippeddata, &packetdata[BASE_HEADER_SIZE],
22282229
strippeddata.getSize());
2229-
2230+
22302231
try{
22312232
// Process it (the result is some data with no headers made by us)
22322233
SharedBuffer<u8> resultdata = processPacket
22332234
(channel, strippeddata, peer_id, channelnum, false);
2234-
2235+
22352236
LOG(dout_con<<m_connection->getDesc()
22362237
<<" ProcessPacket from peer_id: " << peer_id
22372238
<< ",channel: " << (channelnum & 0xFF) << ", returned "
22382239
<< resultdata.getSize() << " bytes" <<std::endl);
2239-
2240+
22402241
ConnectionEvent e;
22412242
e.dataReceived(peer_id, resultdata);
22422243
m_connection->putEvent(e);
@@ -2854,11 +2855,11 @@ bool Connection::Connected()
28542855

28552856
if(m_peers.size() != 1)
28562857
return false;
2857-
2858+
28582859
std::map<u16, Peer*>::iterator node = m_peers.find(PEER_ID_SERVER);
28592860
if(node == m_peers.end())
28602861
return false;
2861-
2862+
28622863
if(m_peer_id == PEER_ID_INEXISTENT)
28632864
return false;
28642865

@@ -3114,4 +3115,3 @@ std::list<u16> Connection::getPeerIDs()
31143115
}
31153116

31163117
} // namespace
3117-

‎src/gettext.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,12 @@ inline wchar_t* chartowchar_t(const char *str)
6868
MultiByteToWideChar( CP_UTF8, 0, (LPCSTR) str, -1, (WCHAR *) nstr, nResult );
6969
}
7070
#else
71-
size_t l = strlen(str)+1;
72-
nstr = new wchar_t[l];
71+
size_t l = strlen(str);
72+
nstr = new wchar_t[l+1];
7373

7474
std::wstring intermediate = narrow_to_wide(str);
75-
memset(nstr,0,l);
76-
memcpy(nstr,intermediate.c_str(),l*sizeof(wchar_t));
75+
memset(nstr, 0, (l+1)*sizeof(wchar_t));
76+
memcpy(nstr, intermediate.c_str(), l*sizeof(wchar_t));
7777
#endif
7878

7979
return nstr;

‎src/guiFormSpecMenu.cpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ GUIFormSpecMenu::GUIFormSpecMenu(irr::IrrlichtDevice* dev,
8181
m_selected_amount(0),
8282
m_selected_dragging(false),
8383
m_tooltip_element(NULL),
84+
m_old_tooltip_id(-1),
8485
m_allowclose(true),
8586
m_lock(false),
8687
m_form_src(fsrc),
@@ -1301,7 +1302,7 @@ void GUIFormSpecMenu::parseImageButton(parserData* data,std::string element,
13011302
if (spec.fname == data->focused_fieldname) {
13021303
Environment->setFocus(e);
13031304
}
1304-
1305+
13051306
e->setUseAlphaChannel(true);
13061307
e->setImage(texture);
13071308
e->setPressedImage(pressed_texture);
@@ -1800,7 +1801,7 @@ void GUIFormSpecMenu::regenerateGui(v2u32 screensize)
18001801
m_fields.clear();
18011802
m_boxes.clear();
18021803
m_tooltips.clear();
1803-
1804+
18041805
// Set default values (fits old formspec values)
18051806
m_bgcolor = video::SColor(140,0,0,0);
18061807
m_bgfullscreen = false;
@@ -1810,7 +1811,7 @@ void GUIFormSpecMenu::regenerateGui(v2u32 screensize)
18101811

18111812
m_default_tooltip_bgcolor = video::SColor(255,110,130,60);
18121813
m_default_tooltip_color = video::SColor(255,255,255,255);
1813-
1814+
18141815
m_slotbordercolor = video::SColor(200,0,0,0);
18151816
m_slotborder = false;
18161817

@@ -2828,7 +2829,7 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event)
28282829
}
28292830

28302831
}
2831-
2832+
28322833
if(event.EventType==EET_MOUSE_INPUT_EVENT
28332834
&& event.MouseInput.Event != EMIE_MOUSE_MOVED) {
28342835
// Mouse event other than movement

‎src/nodedef.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ void NodeBox::deSerialize(std::istream &is)
117117
void TileDef::serialize(std::ostream &os, u16 protocol_version) const
118118
{
119119
if(protocol_version >= 17)
120-
writeU8(os, 1);
120+
writeU8(os, 1);
121121
else
122122
writeU8(os, 0);
123123
os<<serializeString(name);
@@ -560,7 +560,7 @@ class CNodeDefManager: public IWritableNodeDefManager
560560
for (ItemGroupList::const_iterator i = def.groups.begin();
561561
i != def.groups.end(); ++i) {
562562
std::string group_name = i->first;
563-
563+
564564
std::map<std::string, GroupItems>::iterator
565565
j = m_group_to_items.find(group_name);
566566
if (j == m_group_to_items.end()) {
@@ -1018,4 +1018,3 @@ void ContentFeatures::deSerializeOld(std::istream &is, int version)
10181018
throw SerializationError("unsupported ContentFeatures version");
10191019
}
10201020
}
1021-

0 commit comments

Comments
 (0)
Please sign in to comment.