Core/Packets: Fixed exceptions being incorrectly thrown when appending empty strings to packets

Closes #5486
Closes #5495
This commit is contained in:
Shauren
2012-02-29 20:12:11 +01:00
parent 3a4ec8a0b8
commit 03a7a80687
2 changed files with 5 additions and 29 deletions
-22
View File
@@ -1,22 +0,0 @@
/*
* Copyright (C) 2008-2012 TrinityCore <http://www.trinitycore.org/>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "ByteBuffer.h"
void ByteBufferException::PrintError() const
{
}
+5 -7
View File
@@ -178,14 +178,17 @@ class ByteBuffer
ByteBuffer &operator<<(const std::string &value) ByteBuffer &operator<<(const std::string &value)
{ {
append((uint8 const*)value.c_str(), value.length()); if (size_t len = value.length())
append((uint8 const*)value.c_str(), len);
append((uint8)0); append((uint8)0);
return *this; return *this;
} }
ByteBuffer &operator<<(const char *str) ByteBuffer &operator<<(const char *str)
{ {
append((uint8 const*)str, str ? strlen(str) : 0); size_t len = 0;
if (str && (len = strlen(str)))
append((uint8 const*)str, len);
append((uint8)0); append((uint8)0);
return *this; return *this;
} }
@@ -372,11 +375,6 @@ class ByteBuffer
_storage.reserve(ressize); _storage.reserve(ressize);
} }
void append(const std::string& str)
{
append((uint8 const*)str.c_str(), str.size() + 1);
}
void append(const char *src, size_t cnt) void append(const char *src, size_t cnt)
{ {
return append((const uint8 *)src, cnt); return append((const uint8 *)src, cnt);