BOOL LLDataPackerAsciiBuffer::packF32(const F32 value, const char *name) { BOOL success = TRUE; writeIndentedName(name); int numCopied = 0; if (mWriteEnabled) { numCopied = snprintf(mCurBufferp,getBufferSize()-getCurrentSize(),"%f\n", value); /* Flawfinder: ignore */ } else { numCopied = snprintf(DUMMY_BUFFER, sizeof(DUMMY_BUFFER), "%f\n", value); /* Flawfinder: ignore */ } // snprintf returns number of bytes that would have been written // had the output not being truncated. In that case, it will // return either -1 or value >= passed in size value . So a check needs to be added // to detect truncation, and if there is any, only account for the // actual number of bytes written..and not what could have been // written. if (numCopied < 0 || numCopied > getBufferSize()-getCurrentSize()) { numCopied = getBufferSize()-getCurrentSize(); llwarns << "LLDataPackerAsciiBuffer::packF32: val truncated: " << llendl; } mCurBufferp += numCopied; return success; }
BOOL LLDataPackerAsciiFile::packBinaryDataFixed(const U8 *value, S32 size, const char *name) { BOOL success = TRUE; writeIndentedName(name); if (mFP) { S32 i; for (i = 0; i < size; i++) { fprintf(mFP, "%02x ", value[i]); } fprintf(mFP, "\n"); } else if (mOutputStream) { char buffer[32]; /*Flawfinder: ignore*/ S32 i; for (i = 0; i < size; i++) { snprintf(buffer, sizeof(buffer), "%02x ", value[i]); /* Flawfinder: ignore */ *mOutputStream << buffer; } *mOutputStream << "\n"; } return success; }
//--------------------------------------------------------------------------- // LLDataPackerAsciiBuffer implementation //--------------------------------------------------------------------------- BOOL LLDataPackerAsciiBuffer::packString(const char *value, const char *name) { BOOL success = TRUE; writeIndentedName(name); int numCopied = 0; if (mWriteEnabled) { numCopied = snprintf(mCurBufferp,getBufferSize()-getCurrentSize(),"%s\n", value); /* Flawfinder: ignore */ } else { numCopied = (S32)strlen(value) + 1; /*Flawfinder: ignore*/ } // snprintf returns number of bytes that would have been written // had the output not being truncated. In that case, it will // return either -1 or value >= passed in size value . So a check needs to be added // to detect truncation, and if there is any, only account for the // actual number of bytes written..and not what could have been // written. if (numCopied < 0 || numCopied > getBufferSize()-getCurrentSize()) { // *NOTE: I believe we need to mark a failure bit at this point. numCopied = getBufferSize()-getCurrentSize(); llwarns << "LLDataPackerAsciiBuffer::packString: string truncated: " << value << llendl; } mCurBufferp += numCopied; return success; }
BOOL LLDataPackerAsciiBuffer::packUUID(const LLUUID &value, const char *name) { BOOL success = TRUE; writeIndentedName(name); int numCopied = 0; if (mWriteEnabled) { char tmp_str[64]; /* Flawfinder: ignore */ value.toString(tmp_str); numCopied = snprintf(mCurBufferp,getBufferSize()-getCurrentSize(),"%s\n", tmp_str); /* Flawfinder: ignore */ } else { numCopied = 64 + 1; // UUID + newline } // snprintf returns number of bytes that would have been written // had the output not being truncated. In that case, it will // return either -1 or value >= passed in size value . So a check needs to be added // to detect truncation, and if there is any, only account for the // actual number of bytes written..and not what could have been // written. if (numCopied < 0 || numCopied > getBufferSize()-getCurrentSize()) { numCopied = getBufferSize()-getCurrentSize(); llwarns << "LLDataPackerAsciiBuffer::packUUID: truncated: " << llendl; success = FALSE; } mCurBufferp += numCopied; return success; }
BOOL LLDataPackerAsciiFile::packVector4(const LLVector4 &value, const char *name) { BOOL success = TRUE; writeIndentedName(name); if (mFP) { fprintf(mFP,"%f %f %f %f\n", value.mV[0], value.mV[1], value.mV[2], value.mV[3]); } else if (mOutputStream) { *mOutputStream << convertF32ToString(value.mV[0]) << " " << convertF32ToString(value.mV[1]) << " " << convertF32ToString(value.mV[2]) << " " << convertF32ToString(value.mV[3]) << "\n"; } return success; }
BOOL LLDataPackerAsciiFile::packColor4U(const LLColor4U &value, const char *name) { BOOL success = TRUE; writeIndentedName(name); if (mFP) { fprintf(mFP,"%d %d %d %d\n", value.mV[0], value.mV[1], value.mV[2], value.mV[3]); } else if (mOutputStream) { *mOutputStream << (S32)(value.mV[0]) << " " << (S32)(value.mV[1]) << " " << (S32)(value.mV[2]) << " " << (S32)(value.mV[3]) << "\n"; } return success; }
BOOL LLDataPackerAsciiFile::packF32(const F32 value, const char *name) { BOOL success = TRUE; writeIndentedName(name); if (mFP) { fprintf(mFP,"%f\n", value); } else if (mOutputStream) { *mOutputStream <<"" << convertF32ToString(value) << "\n"; } return success; }
BOOL LLDataPackerAsciiFile::packU16(const U16 value, const char *name) { BOOL success = TRUE; writeIndentedName(name); if (mFP) { fprintf(mFP,"%d\n", value); } else if (mOutputStream) { *mOutputStream <<"" << value << "\n"; } return success; }
//--------------------------------------------------------------------------- // LLDataPackerAsciiFile implementation //--------------------------------------------------------------------------- BOOL LLDataPackerAsciiFile::packString(const std::string& value, const char *name) { BOOL success = TRUE; writeIndentedName(name); if (mFP) { fprintf(mFP,"%s\n", value.c_str()); } else if (mOutputStream) { *mOutputStream << value << "\n"; } return success; }
BOOL LLDataPackerAsciiFile::packUUID(const LLUUID &value, const char *name) { BOOL success = TRUE; writeIndentedName(name); char tmp_str[64]; /*Flawfinder: ignore */ value.toString(tmp_str); if (mFP) { fprintf(mFP,"%s\n", tmp_str); } else if (mOutputStream) { *mOutputStream <<"" << tmp_str << "\n"; } return success; }
BOOL LLDataPackerAsciiFile::packU8(const U8 value, const char *name) { BOOL success = TRUE; writeIndentedName(name); if (mFP) { fprintf(mFP,"%d\n", value); } else if (mOutputStream) { // We have to cast this to an integer because streams serialize // bytes as bytes - not as text. *mOutputStream << (S32)value << "\n"; } return success; }
BOOL LLDataPackerAsciiFile::packUUID(const LLUUID &value, const char *name) { BOOL success = TRUE; writeIndentedName(name); std::string tmp_str; value.toString(tmp_str); if (mFP) { fprintf(mFP,"%s\n", tmp_str.c_str()); } else if (mOutputStream) { *mOutputStream <<"" << tmp_str << "\n"; } return success; }
BOOL LLDataPackerAsciiBuffer::packBinaryDataFixed(const U8 *value, S32 size, const char *name) { BOOL success = TRUE; writeIndentedName(name); if (mWriteEnabled) { S32 i; int numCopied = 0; BOOL bBufferFull = FALSE; for (i = 0; i < size && !bBufferFull; i++) { numCopied = snprintf(mCurBufferp, getBufferSize()-getCurrentSize(), "%02x ", value[i]); /* Flawfinder: ignore */ if (numCopied < 0 || numCopied > getBufferSize()-getCurrentSize()) { numCopied = getBufferSize()-getCurrentSize(); llwarns << "LLDataPackerAsciiBuffer::packBinaryDataFixed: data truncated: " << llendl; bBufferFull = TRUE; } mCurBufferp += numCopied; } if (!bBufferFull) { numCopied = snprintf(mCurBufferp,getBufferSize()-getCurrentSize(), "\n"); /* Flawfinder: ignore */ if (numCopied < 0 || numCopied > getBufferSize()-getCurrentSize()) { numCopied = getBufferSize()-getCurrentSize(); llwarns << "LLDataPackerAsciiBuffer::packBinaryDataFixed: newline truncated: " << llendl; } mCurBufferp += numCopied; } } else { int numCopied = 2 * size + 1; //hex bytes plus newline if (numCopied > getBufferSize()-getCurrentSize()) { numCopied = getBufferSize()-getCurrentSize(); } mCurBufferp += numCopied; } return success; }
BOOL LLDataPackerAsciiBuffer::packBinaryData(const U8 *value, S32 size, const char *name) { BOOL success = TRUE; writeIndentedName(name); int numCopied = 0; if (mWriteEnabled) { numCopied = snprintf(mCurBufferp,getBufferSize()-getCurrentSize(),"%010d ", size); /* Flawfinder: ignore */ // snprintf returns number of bytes that would have been // written had the output not being truncated. In that case, // it will retuen >= passed in size value. so a check needs // to be added to detect truncation, and if there is any, only // account for the actual number of bytes written..and not // what could have been written. if (numCopied < 0 || numCopied > getBufferSize()-getCurrentSize()) { numCopied = getBufferSize()-getCurrentSize(); llwarns << "LLDataPackerAsciiBuffer::packBinaryData: number truncated: " << size << llendl; } mCurBufferp += numCopied; S32 i; BOOL bBufferFull = FALSE; for (i = 0; i < size && !bBufferFull; i++) { numCopied = snprintf(mCurBufferp, getBufferSize()-getCurrentSize(), "%02x ", value[i]); /* Flawfinder: ignore */ if (numCopied < 0 || numCopied > getBufferSize()-getCurrentSize()) { numCopied = getBufferSize()-getCurrentSize(); llwarns << "LLDataPackerAsciiBuffer::packBinaryData: data truncated: " << llendl; bBufferFull = TRUE; } mCurBufferp += numCopied; } if (!bBufferFull) { numCopied = snprintf(mCurBufferp,getBufferSize()-getCurrentSize(), "\n"); /* Flawfinder: ignore */ if (numCopied < 0 || numCopied > getBufferSize()-getCurrentSize()) { numCopied = getBufferSize()-getCurrentSize(); llwarns << "LLDataPackerAsciiBuffer::packBinaryData: newline truncated: " << llendl; } mCurBufferp += numCopied; } } else { // why +10 ?? XXXCHECK numCopied = 10 + 1; // size plus newline numCopied += size; if (numCopied > getBufferSize()-getCurrentSize()) { numCopied = getBufferSize()-getCurrentSize(); } mCurBufferp += numCopied; } return success; }