summaryrefslogtreecommitdiff
path: root/indra/llmessage/lldatapacker.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'indra/llmessage/lldatapacker.cpp')
-rw-r--r--indra/llmessage/lldatapacker.cpp80
1 files changed, 46 insertions, 34 deletions
diff --git a/indra/llmessage/lldatapacker.cpp b/indra/llmessage/lldatapacker.cpp
index 2ebd1b7176..3385d7c2e2 100644
--- a/indra/llmessage/lldatapacker.cpp
+++ b/indra/llmessage/lldatapacker.cpp
@@ -2,30 +2,25 @@
* @file lldatapacker.cpp
* @brief Data packer implementation.
*
- * $LicenseInfo:firstyear=2006&license=viewergpl$
- *
- * Copyright (c) 2006-2007, Linden Research, Inc.
- *
+ * $LicenseInfo:firstyear=2006&license=viewerlgpl$
* Second Life Viewer Source Code
- * The source code in this file ("Source Code") is provided by Linden Lab
- * to you under the terms of the GNU General Public License, version 2.0
- * ("GPL"), unless you have obtained a separate licensing agreement
- * ("Other License"), formally executed by you and Linden Lab. Terms of
- * the GPL can be found in doc/GPL-license.txt in this distribution, or
- * online at http://secondlife.com/developers/opensource/gplv2
+ * Copyright (C) 2010, Linden Research, Inc.
*
- * There are special exceptions to the terms and conditions of the GPL as
- * it is applied to this Source Code. View the full text of the exception
- * in the file doc/FLOSS-exception.txt in this software distribution, or
- * online at http://secondlife.com/developers/opensource/flossexception
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License only.
*
- * By copying, modifying or distributing this software, you acknowledge
- * that you have read and understood your obligations described above,
- * and agree to abide by those obligations.
+ * This library 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
+ * Lesser General Public License for more details.
*
- * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
- * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
- * COMPLETENESS OR PERFORMANCE.
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
@@ -54,6 +49,18 @@ LLDataPacker::LLDataPacker() : mPassFlags(0), mWriteEnabled(FALSE)
{
}
+//virtual
+void LLDataPacker::reset()
+{
+ llerrs << "Using unimplemented datapacker reset!" << llendl;
+}
+
+//virtual
+void LLDataPacker::dumpBufferToLog()
+{
+ llerrs << "dumpBufferToLog not implemented for this type!" << llendl;
+}
+
BOOL LLDataPacker::packFixed(const F32 value, const char *name,
const BOOL is_signed, const U32 int_bits, const U32 frac_bits)
{
@@ -170,16 +177,16 @@ BOOL LLDataPacker::unpackFixed(F32 &value, const char *name,
// LLDataPackerBinaryBuffer implementation
//---------------------------------------------------------------------------
-BOOL LLDataPackerBinaryBuffer::packString(const char *value, const char *name)
+BOOL LLDataPackerBinaryBuffer::packString(const std::string& value, const char *name)
{
BOOL success = TRUE;
- S32 length = (S32)strlen(value) + 1; /*Flawfinder: ignore*/
+ S32 length = value.length()+1;
success &= verifyLength(length, name);
if (mWriteEnabled)
{
- htonmemcpy(mCurBufferp, value, MVT_VARIABLE, length);
+ htonmemcpy(mCurBufferp, value.c_str(), MVT_VARIABLE, length);
}
mCurBufferp += length;
return success;
@@ -577,18 +584,18 @@ void LLDataPackerBinaryBuffer::dumpBufferToLog()
//---------------------------------------------------------------------------
// LLDataPackerAsciiBuffer implementation
//---------------------------------------------------------------------------
-BOOL LLDataPackerAsciiBuffer::packString(const char *value, const char *name)
+BOOL LLDataPackerAsciiBuffer::packString(const std::string& value, const char *name)
{
BOOL success = TRUE;
writeIndentedName(name);
int numCopied = 0;
if (mWriteEnabled)
{
- numCopied = snprintf(mCurBufferp,getBufferSize()-getCurrentSize(),"%s\n", value); /* Flawfinder: ignore */
+ numCopied = snprintf(mCurBufferp,getBufferSize()-getCurrentSize(),"%s\n", value.c_str()); /* Flawfinder: ignore */
}
else
{
- numCopied = (S32)strlen(value) + 1; /*Flawfinder: ignore*/
+ numCopied = value.length() + 1; /*Flawfinder: ignore*/
}
// snprintf returns number of bytes that would have been written
@@ -1242,9 +1249,9 @@ BOOL LLDataPackerAsciiBuffer::packUUID(const LLUUID &value, const char *name)
int numCopied = 0;
if (mWriteEnabled)
{
- char tmp_str[64]; /* Flawfinder: ignore */
+ std::string tmp_str;
value.toString(tmp_str);
- numCopied = snprintf(mCurBufferp,getBufferSize()-getCurrentSize(),"%s\n", tmp_str); /* Flawfinder: ignore */
+ numCopied = snprintf(mCurBufferp,getBufferSize()-getCurrentSize(),"%s\n", tmp_str.c_str()); /* Flawfinder: ignore */
}
else
{
@@ -1376,13 +1383,13 @@ std::string convertF32ToString(F32 val)
//---------------------------------------------------------------------------
// LLDataPackerAsciiFile implementation
//---------------------------------------------------------------------------
-BOOL LLDataPackerAsciiFile::packString(const char *value, const char *name)
+BOOL LLDataPackerAsciiFile::packString(const std::string& value, const char *name)
{
BOOL success = TRUE;
writeIndentedName(name);
if (mFP)
{
- fprintf(mFP,"%s\n", value);
+ fprintf(mFP,"%s\n", value.c_str());
}
else if (mOutputStream)
{
@@ -1829,11 +1836,11 @@ BOOL LLDataPackerAsciiFile::packUUID(const LLUUID &value, const char *name)
{
BOOL success = TRUE;
writeIndentedName(name);
- char tmp_str[64]; /*Flawfinder: ignore */
+ std::string tmp_str;
value.toString(tmp_str);
if (mFP)
{
- fprintf(mFP,"%s\n", tmp_str);
+ fprintf(mFP,"%s\n", tmp_str.c_str());
}
else if (mOutputStream)
{
@@ -1877,7 +1884,7 @@ void LLDataPackerAsciiFile::writeIndentedName(const char *name)
}
else if (mOutputStream)
{
- *mOutputStream << indent_buf.c_str() << name << "\t";
+ *mOutputStream << indent_buf << name << "\t";
}
}
@@ -1895,7 +1902,12 @@ BOOL LLDataPackerAsciiFile::getValueStr(const char *name, char *out_value, S32 v
if (mFP)
{
fpos_t last_pos;
- fgetpos(mFP, &last_pos);
+ if (0 != fgetpos(mFP, &last_pos)) // 0==success for fgetpos
+ {
+ llwarns << "Data packer failed to fgetpos" << llendl;
+ return FALSE;
+ }
+
if (fgets(buffer, DP_BUFSIZE, mFP) == NULL)
{
buffer[0] = '\0';