Remove the “len” defaulted parameter from CommandReturnObject::AppendMessage, AppendWarning and AppendError. Nobody was using them, and it meant if you accidentally used the AppendWarning when you meant AppendWarningWithFormat with an integer in the format string, it would compile and then return your string plus some unknown amount of junk.

llvm-svn: 170266
This commit is contained in:
Jim Ingham 2012-12-15 02:40:54 +00:00
parent 2e1f745da7
commit 17fafa155c
4 changed files with 26 additions and 23 deletions

View File

@ -118,7 +118,7 @@ public:
Clear();
void
AppendMessage (const char *in_string, int len = -1);
AppendMessage (const char *in_string);
void
AppendMessageWithFormat (const char *format, ...) __attribute__ ((format (printf, 2, 3)));
@ -127,13 +127,13 @@ public:
AppendRawWarning (const char *in_string, int len = -1);
void
AppendWarning (const char *in_string, int len = -1);
AppendWarning (const char *in_string);
void
AppendWarningWithFormat (const char *format, ...) __attribute__ ((format (printf, 2, 3)));
void
AppendError (const char *in_string, int len = -1);
AppendError (const char *in_string);
void
AppendRawError (const char *in_string, int len = -1);

View File

@ -281,7 +281,17 @@ SBCommandReturnObject::PutCString(const char* string, int len)
{
if (m_opaque_ap.get())
{
m_opaque_ap->AppendMessage(string, len);
if (len == 0)
{
return;
}
else if (len > 0)
{
std::string buffer(string, len);
m_opaque_ap->AppendMessage(buffer.c_str());
}
else
m_opaque_ap->AppendMessage(string);
}
}

View File

@ -876,7 +876,7 @@ protected:
comp_unit->GetDirectory().GetCString(),
comp_unit->GetFilename().GetCString());
else
result.AppendError ("no debug information for frame %u\n", frame->GetFrameIndex());
result.AppendErrorWithFormat ("no debug information for frame %u\n", frame->GetFrameIndex());
}
else
result.AppendError ("'target variable' takes one or more global variable names as arguments\n");
@ -3152,13 +3152,13 @@ protected:
}
else
{
result.AppendError ("Couldn't find module matching address: 0x%" PRIx64 ".", m_options.m_module_addr);
result.AppendErrorWithFormat ("Couldn't find module matching address: 0x%" PRIx64 ".", m_options.m_module_addr);
result.SetStatus (eReturnStatusFailed);
}
}
else
{
result.AppendError ("Couldn't find module containing address: 0x%" PRIx64 ".", m_options.m_module_addr);
result.AppendErrorWithFormat ("Couldn't find module containing address: 0x%" PRIx64 ".", m_options.m_module_addr);
result.SetStatus (eReturnStatusFailed);
}
}

View File

@ -104,24 +104,19 @@ CommandReturnObject::AppendWarningWithFormat (const char *format, ...)
}
void
CommandReturnObject::AppendMessage (const char *in_string, int len)
CommandReturnObject::AppendMessage (const char *in_string)
{
if (!in_string || len == 0)
if (!in_string || *in_string == '\0')
return;
if (len < 0)
GetOutputStream().Printf("%s\n", in_string);
else
GetOutputStream().Printf("%*.*s\n", len, len, in_string);
GetOutputStream().Printf("%s\n", in_string);
}
void
CommandReturnObject::AppendWarning (const char *in_string, int len)
CommandReturnObject::AppendWarning (const char *in_string)
{
if (!in_string)
if (!in_string || *in_string == '\0')
return;
if (len < 0)
len = ::strlen (in_string);
GetErrorStream().Printf("warning: %*.*s\n", len, len, in_string);
GetErrorStream().Printf("warning: %s\n", in_string);
}
// Similar to AppendWarning, but do not prepend 'warning: ' to message, and
@ -138,13 +133,11 @@ CommandReturnObject::AppendRawWarning (const char *in_string, int len)
}
void
CommandReturnObject::AppendError (const char *in_string, int len)
CommandReturnObject::AppendError (const char *in_string)
{
if (!in_string)
if (!in_string || *in_string == '\0')
return;
if (len < 0)
len = ::strlen (in_string);
GetErrorStream().Printf ("error: %*.*s\n", len, len, in_string);
GetErrorStream().Printf ("error: %s\n", in_string);
}
void