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


git-svn-id: svn://10.0.0.236/trunk@134044 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
kin%netscape.com
2002-11-18 15:43:19 +00:00
parent 8fa2ad5646
commit 9b97540558
4 changed files with 52 additions and 53 deletions

View File

@@ -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");