Fix for bug 173553: flawfinder warnings in editor/libeditor/html/nsHTMLEditorLog.cpp

Changed all occurrences of sprintf() to snprintf(). Removed format arg from WriteInt().

r=brade@netscape.com  sr=sfraser@netscape.com
This commit is contained in:
kin%netscape.com 2002-11-18 15:43:19 +00:00
Родитель a6af7718a1
Коммит adda10c39e
4 изменённых файлов: 52 добавлений и 53 удалений

Просмотреть файл

@ -130,7 +130,7 @@ nsEditorTxnLog::DidDo(nsITransactionManager *aTxMgr, nsITransaction *aTransactio
Write("DidDo: ");
WriteTransaction(aTransaction);
Write("(");
WriteInt("%d", aDoResult);
WriteInt(aDoResult);
Write(")\n");
Flush();
@ -174,13 +174,13 @@ nsEditorTxnLog::DidUndo(nsITransactionManager *aTxMgr, nsITransaction *aTransact
Write("DidUndo: ");
WriteTransaction(aTransaction);
Write("(");
WriteInt("%d", aUndoResult);
WriteInt(aUndoResult);
Write(")\n");
}
else
{
Write("EndUndoBatch (");
WriteInt("%d", aUndoResult);
WriteInt(aUndoResult);
Write(")\n");
}
@ -226,13 +226,13 @@ nsEditorTxnLog::DidRedo(nsITransactionManager *aTxMgr, nsITransaction *aTransact
Write("DidRedo: ");
WriteTransaction(aTransaction);
Write(" (");
WriteInt("%d", aRedoResult);
WriteInt(aRedoResult);
Write(")\n");
}
else
{
Write("DidRedoBatch (");
WriteInt("%d", aRedoResult);
WriteInt(aRedoResult);
Write(")\n");
}
@ -250,7 +250,7 @@ nsEditorTxnLog::WillBeginBatch(nsITransactionManager *aTxMgr, PRBool *aInterrupt
PrintIndent(mIndentLevel);
Write("WillBeginBatch: ");
WriteInt("%d", mBatchCount);
WriteInt(mBatchCount);
Write("\n");
Flush();
@ -266,9 +266,9 @@ nsEditorTxnLog::DidBeginBatch(nsITransactionManager *aTxMgr, nsresult aResult)
PrintIndent(mIndentLevel++);
Write("DidBeginBatch: ");
WriteInt("%d", mBatchCount++);
WriteInt(mBatchCount++);
Write(" (");
WriteInt("%d", aResult);
WriteInt(aResult);
Write(")\n");
Flush();
@ -284,7 +284,7 @@ nsEditorTxnLog::WillEndBatch(nsITransactionManager *aTxMgr, PRBool *aInterrupt)
PrintIndent(--mIndentLevel);
Write("WillEndBatch: ");
WriteInt("%d", --mBatchCount);
WriteInt(--mBatchCount);
Write("\n");
Flush();
@ -300,9 +300,9 @@ nsEditorTxnLog::DidEndBatch(nsITransactionManager *aTxMgr, nsresult aResult)
PrintIndent(mIndentLevel);
Write("DidEndBatch: ");
WriteInt("%d", mBatchCount);
WriteInt(mBatchCount);
Write(" (");
WriteInt("%d", aResult);
WriteInt(aResult);
Write(")\n");
Flush();
@ -342,7 +342,7 @@ nsEditorTxnLog::DidMerge(nsITransactionManager *aTxMgr, nsITransaction *aTopTran
Write(" (");
Write(aDidMerge ? "TRUE" : "FALSE");
Write(", ");
WriteInt("%d", aMergeResult);
WriteInt(aMergeResult);
Write(")\n");
Flush();
@ -388,21 +388,22 @@ nsEditorTxnLog::Write(const char *aBuffer)
if (mEditorLog)
mEditorLog->Write(aBuffer);
else
printf(aBuffer);
{
PRInt32 len = strlen(aBuffer);
if (len > 0)
fwrite(aBuffer, 1, len, stdout);
}
return NS_OK;
}
nsresult
nsEditorTxnLog::WriteInt(const char *aFormat, PRInt32 aInt)
nsEditorTxnLog::WriteInt(PRInt32 aInt)
{
if (!aFormat)
return NS_ERROR_NULL_POINTER;
if (mEditorLog)
mEditorLog->WriteInt(aFormat, aInt);
mEditorLog->WriteInt(aInt);
else
printf(aFormat, aInt);
printf("%d", aInt);
return NS_OK;
}

Просмотреть файл

@ -89,7 +89,7 @@ private:
/* nsEditorTxnLog private methods. */
nsresult PrintIndent(PRInt32 aIndentLevel);
nsresult Write(const char *aBuffer);
nsresult WriteInt(const char *aFormat, PRInt32 aInt);
nsresult WriteInt(PRInt32 aInt);
nsresult WriteTransaction(nsITransaction *aTransaction);
nsresult Flush();
};

Просмотреть файл

@ -49,6 +49,7 @@
#include "nsHTMLEditorLog.h"
#include "nsCOMPtr.h"
#include "nsCRT.h"
#include "prprf.h"
#include "nsEditorTxnLog.h"
@ -154,7 +155,7 @@ nsHTMLEditorLog::DeleteSelection(nsIEditor::EDirection aAction)
{
PrintSelection();
Write("GetCurrentEditor().deleteSelection(");
WriteInt("%d", aAction);
WriteInt(aAction);
Write(");\n");
Flush();
@ -206,7 +207,7 @@ nsHTMLEditorLog::Undo(PRUint32 aCount)
if (!mLocked && mFileStream)
{
Write("GetCurrentEditor().undo(");
WriteInt("%d", aCount);
WriteInt(aCount);
Write(");\n");
Flush();
}
@ -222,7 +223,7 @@ nsHTMLEditorLog::Redo(PRUint32 aCount)
if (!mLocked && mFileStream)
{
Write("GetCurrentEditor().redo(");
WriteInt("%d", aCount);
WriteInt(aCount);
Write(");\n");
Flush();
}
@ -339,7 +340,7 @@ nsHTMLEditorLog::Paste(PRInt32 aClipboardType)
{
PrintSelection();
Write("GetCurrentEditor().paste(");
WriteInt("%d", aClipboardType);
WriteInt(aClipboardType);
Write(");\n");
Flush();
}
@ -356,7 +357,7 @@ nsHTMLEditorLog::PasteAsQuotation(PRInt32 aClipboardType)
{
PrintSelection();
Write("GetCurrentEditor().pasteAsQuotation(");
WriteInt("%d", aClipboardType);
WriteInt(aClipboardType);
Write(");\n");
Flush();
}
@ -373,7 +374,7 @@ nsHTMLEditorLog::PasteAsPlaintextQuotation(PRInt32 aClipboardType)
{
PrintSelection();
Write("GetCurrentEditor().pasteAsQuotation(");
WriteInt("%d", aClipboardType);
WriteInt(aClipboardType);
Write(");\n");
Flush();
}
@ -393,7 +394,7 @@ nsHTMLEditorLog::PasteAsCitedQuotation(const nsAString& aCitation,
Write("GetCurrentEditor().pasteAsCitedQuotation(\"");
PrintUnicode(aCitation);
Write("\", ");
WriteInt("%d", aClipboardType);
WriteInt(aClipboardType);
Write(");\n");
Flush();
}
@ -510,7 +511,7 @@ nsHTMLEditorLog:: InsertTableCell(PRInt32 aNumber, PRBool aAfter)
if (!mLocked && mFileStream)
{
Write("GetCurrentEditor().insertTableCell(");
WriteInt("%d", aNumber);
WriteInt(aNumber);
Write(", ");
Write(aAfter ? "true" : "false");
Write(");\n");
@ -529,7 +530,7 @@ nsHTMLEditorLog:: InsertTableColumn(PRInt32 aNumber, PRBool aAfter)
if (!mLocked && mFileStream)
{
Write("GetCurrentEditor().insertTableColumn(");
WriteInt("%d", aNumber);
WriteInt(aNumber);
Write(", ");
Write(aAfter ? "true" : "false");
Write(");\n");
@ -548,7 +549,7 @@ nsHTMLEditorLog:: InsertTableRow(PRInt32 aNumber, PRBool aAfter)
if (!mLocked && mFileStream)
{
Write("GetCurrentEditor().insertTableRow(");
WriteInt("%d", aNumber);
WriteInt(aNumber);
Write(", ");
Write(aAfter ? "true" : "false");
Write(");\n");
@ -580,7 +581,7 @@ nsHTMLEditorLog:: DeleteTableCell(PRInt32 aNumber)
if (!mLocked && mFileStream)
{
Write("GetCurrentEditor().deleteTableCell(");
WriteInt("%d", aNumber);
WriteInt(aNumber);
Write(");\n");
Flush();
}
@ -611,7 +612,7 @@ nsHTMLEditorLog:: DeleteTableColumn(PRInt32 aNumber)
if (!mLocked && mFileStream)
{
Write("GetCurrentEditor().deleteTableColumn(");
WriteInt("%d", aNumber);
WriteInt(aNumber);
Write(");\n");
Flush();
}
@ -628,7 +629,7 @@ nsHTMLEditorLog:: DeleteTableRow(PRInt32 aNumber)
if (!mLocked && mFileStream)
{
Write("GetCurrentEditor().deleteTableRow(");
WriteInt("%d", aNumber);
WriteInt(aNumber);
Write(");\n");
Flush();
}
@ -931,14 +932,11 @@ nsHTMLEditorLog::Write(const char *aBuffer)
}
nsresult
nsHTMLEditorLog::WriteInt(const char *aFormat, PRInt32 aInt)
nsHTMLEditorLog::WriteInt(PRInt32 aInt)
{
if (!aFormat)
return NS_ERROR_NULL_POINTER;
char buf[256];
sprintf(buf, aFormat, aInt);
PR_snprintf(buf, sizeof(buf), "%d", aInt);
return Write(buf);
}
@ -967,9 +965,9 @@ nsHTMLEditorLog::PrintUnicode(const nsAString &aString)
while(beginIter != endIter)
{
if (nsCRT::IsAsciiAlpha(*beginIter) || nsCRT::IsAsciiDigit(*beginIter) || *beginIter == ' ')
sprintf(buf, "%c", *beginIter);
PR_snprintf(buf, sizeof(buf), "%c", *beginIter);
else
sprintf(buf, "\\u%.4x", *beginIter);
PR_snprintf(buf, sizeof(buf), "\\u%.4x", *beginIter);
nsresult result = Write(buf);
@ -1056,11 +1054,11 @@ nsHTMLEditorLog::PrintSelection()
{
if (j != 0)
Write(", ");
WriteInt("%d", offsetArray[j]);
WriteInt(offsetArray[j]);
}
Write("], ");
WriteInt("%3d", startOffset);
WriteInt(startOffset);
Write("], ");
if (startNode != endNode)
@ -1081,13 +1079,13 @@ nsHTMLEditorLog::PrintSelection()
{
if (j != 0)
Write(", ");
WriteInt("%d", offsetArray[j]);
WriteInt(offsetArray[j]);
}
delete []offsetArray;
Write("], ");
WriteInt("%3d", endOffset);
WriteInt(endOffset);
Write("] ]");
}
@ -1115,7 +1113,7 @@ nsHTMLEditorLog::PrintElementNode(nsIDOMNode *aNode, PRInt32 aDepth)
return result;
Write("n");
WriteInt("%d", aDepth);
WriteInt(aDepth);
Write(" = GetCurrentEditor().editorDocument.createElement(\"");
PrintUnicode(tag);
Write("\");\n");
@ -1174,7 +1172,7 @@ nsHTMLEditorLog::PrintAttributeNode(nsIDOMNode *aNode, PRInt32 aDepth)
return result;
Write("a");
WriteInt("%d", aDepth);
WriteInt(aDepth);
Write(" = GetCurrentEditor().editorDocument.createAttribute(\"");
PrintUnicode(str);
Write("\");\n");
@ -1185,15 +1183,15 @@ nsHTMLEditorLog::PrintAttributeNode(nsIDOMNode *aNode, PRInt32 aDepth)
return result;
Write("a");
WriteInt("%d", aDepth);
WriteInt(aDepth);
Write(".value = \"");
PrintUnicode(str);
Write("\";\n");
Write("n");
WriteInt("%d", aDepth);
WriteInt(aDepth);
Write(".setAttributeNode(a");
WriteInt("%d", aDepth);
WriteInt(aDepth);
Write(");\n");
return NS_OK;
@ -1241,9 +1239,9 @@ nsHTMLEditorLog::PrintNodeChildren(nsIDOMNode *aNode, PRInt32 aDepth)
return result;
Write("n");
WriteInt("%d", aDepth);
WriteInt(aDepth);
Write(".appendChild(n");
WriteInt("%d", aDepth+1);
WriteInt(aDepth+1);
Write(");\n");
}
@ -1268,7 +1266,7 @@ nsHTMLEditorLog::PrintTextNode(nsIDOMNode *aNode, PRInt32 aDepth)
return result;
Write("n");
WriteInt("%d", aDepth);
WriteInt(aDepth);
Write(" = GetCurrentEditor().editorDocument.createTextNode(\"");
PrintUnicode(str);
Write("\");\n");

Просмотреть файл

@ -129,7 +129,7 @@ public:
/* nsHTMLEditorLog public methods. */
nsresult Write(const char *aBuffer);
nsresult WriteInt(const char *aFormat, PRInt32 aInt);
nsresult WriteInt(PRInt32 aInt);
nsresult Flush();
nsresult PrintUnicode(const nsAString &aString);
nsresult PrintSelection();