Change Error::SetErrorStringWithFormat() prototype to use an

__attribute__ format so the compiler knows that this method takes
printf style formatter arguments and checks that it's being used
correctly.  Fix a couple dozen incorrect SetErrorStringWithFormat()
calls throughout the sources.

llvm-svn: 140115
This commit is contained in:
Jason Molenda 2011-09-20 00:26:08 +00:00
parent e65c2ab453
commit 7e589a6011
10 changed files with 23 additions and 22 deletions

View File

@ -266,7 +266,7 @@ public:
/// A printf style format string
//------------------------------------------------------------------
int
SetErrorStringWithFormat (const char *format, ...);
SetErrorStringWithFormat (const char *format, ...) __attribute__ ((format (printf, 2, 3)));
int
SetErrorStringWithVarArg (const char *format, va_list args);

View File

@ -3429,7 +3429,7 @@ public:
m_one_liner = option_arg;
break;
default:
error.SetErrorStringWithFormat ("Unrecognized option %c.");
error.SetErrorStringWithFormat ("Unrecognized option %c.", short_option);
break;
}
return error;

View File

@ -865,7 +865,7 @@ ModuleList::GetSharedModule
if (arch.IsValid())
{
if (uuid_cstr[0])
error.SetErrorStringWithFormat("'%s' does not contain the %s architecture and UUID %s.\n", path, arch.GetArchitectureName(), uuid_cstr[0]);
error.SetErrorStringWithFormat("'%s' does not contain the %s architecture and UUID %s.\n", path, arch.GetArchitectureName(), uuid_cstr);
else
error.SetErrorStringWithFormat("'%s' does not contain the %s architecture.\n", path, arch.GetArchitectureName());
}
@ -941,9 +941,9 @@ ModuleList::GetSharedModule
uuid_cstr[0] = '\0';
if (uuid_cstr[0])
error.SetErrorStringWithFormat("Cannot locate a module for UUID '%s'.\n", uuid_cstr[0]);
error.SetErrorStringWithFormat("Cannot locate a module for UUID '%s'.\n", uuid_cstr);
else
error.SetErrorStringWithFormat("Cannot locate a module.\n", path, arch.GetArchitectureName());
error.SetErrorStringWithFormat("Cannot locate a module.\n");
}
}
}

View File

@ -2134,9 +2134,9 @@ UserSettingsController::UpdateBooleanVariable (VarSetOperationType op,
if (value_cstr == NULL)
err.SetErrorStringWithFormat ("invalid boolean string value (NULL)\n", value_cstr);
err.SetErrorStringWithFormat ("invalid boolean string value (NULL)\n");
else if (value_cstr[0] == '\0')
err.SetErrorStringWithFormat ("invalid boolean string value (empty)\n", value_cstr);
err.SetErrorStringWithFormat ("invalid boolean string value (empty)\n");
else
{
bool new_value = Args::StringToBoolean (value_cstr, false, &success);
@ -2180,9 +2180,9 @@ UserSettingsController::UpdateBooleanOptionValue (const char *value,
error = option_value.SetValueFromCString(value);
if (value == NULL)
error.SetErrorStringWithFormat ("invalid boolean string value (NULL)\n", value);
error.SetErrorStringWithFormat ("invalid boolean string value (NULL)\n");
else if (value[0] == '\0')
error.SetErrorStringWithFormat ("invalid boolean string value (empty)\n", value);
error.SetErrorStringWithFormat ("invalid boolean string value (empty)\n");
else
{
bool new_value = Args::StringToBoolean (value, false, &success);

View File

@ -1053,7 +1053,7 @@ ValueObject::GetValueAsCString ()
m_value_str.swap(sstr.GetString());
else
{
m_error.SetErrorStringWithFormat ("unsufficient data for value (only %u of %u bytes available)",
m_error.SetErrorStringWithFormat ("unsufficient data for value (only %lu of %lu bytes available)",
m_data.GetByteSize(),
GetByteSize());
m_value_str.clear();

View File

@ -1854,7 +1854,7 @@ ClangExpressionDeclMap::DoMaterializeOneRegister
Error write_error (reg_ctx.WriteRegisterValueToMemory(&reg_info, addr, register_byte_size, reg_value));
if (write_error.Fail())
{
err.SetErrorStringWithFormat ("Couldn't write %s to the target: %s", write_error.AsCString());
err.SetErrorStringWithFormat ("Couldn't write %s to the target: %s", reg_info.name, write_error.AsCString());
return false;
}
}

View File

@ -2395,7 +2395,7 @@ DWARFExpression::Evaluate
if (member_bit_incr % 8)
{
if (error_ptr)
error_ptr->SetErrorStringWithFormat("Array increment is not byte aligned", index, size);
error_ptr->SetErrorStringWithFormat("Array increment is not byte aligned");
return false;
}
int64_t member_offset = (int64_t)(member_bit_incr / 8) * index;

View File

@ -96,7 +96,7 @@ PlatformDarwin::ResolveExecutable (const FileSpec &exe_file,
if (resolved_exe_file.Exists())
error.Clear();
else
error.SetErrorStringWithFormat("the platform is not currently connected, and '%s' doesn't exist in the system root.");
error.SetErrorStringWithFormat("the platform is not currently connected, and '%s' doesn't exist in the system root.", resolved_exe_file.GetFilename().AsCString(""));
}
}

View File

@ -745,7 +745,7 @@ StackFrame::GetValueForVariableExpressionPath (const char *var_expr_cstr,
else if (child_index >= synthetic->GetNumChildren() /* synthetic does not have that many values */)
{
valobj_sp->GetExpressionPath (var_expr_path_strm, false);
error.SetErrorStringWithFormat ("array index %i is not valid for \"(%s) %s\"",
error.SetErrorStringWithFormat ("array index %ld is not valid for \"(%s) %s\"",
child_index,
valobj_sp->GetTypeName().AsCString("<invalid type>"),
var_expr_path_strm.GetString().c_str());
@ -756,7 +756,7 @@ StackFrame::GetValueForVariableExpressionPath (const char *var_expr_cstr,
if (!child_valobj_sp)
{
valobj_sp->GetExpressionPath (var_expr_path_strm, false);
error.SetErrorStringWithFormat ("array index %i is not valid for \"(%s) %s\"",
error.SetErrorStringWithFormat ("array index %ld is not valid for \"(%s) %s\"",
child_index,
valobj_sp->GetTypeName().AsCString("<invalid type>"),
var_expr_path_strm.GetString().c_str());
@ -769,7 +769,7 @@ StackFrame::GetValueForVariableExpressionPath (const char *var_expr_cstr,
if (!child_valobj_sp)
{
valobj_sp->GetExpressionPath (var_expr_path_strm, false);
error.SetErrorStringWithFormat ("failed to use pointer as array for index %i for \"(%s) %s\"",
error.SetErrorStringWithFormat ("failed to use pointer as array for index %ld for \"(%s) %s\"",
child_index,
valobj_sp->GetTypeName().AsCString("<invalid type>"),
var_expr_path_strm.GetString().c_str());
@ -784,7 +784,7 @@ StackFrame::GetValueForVariableExpressionPath (const char *var_expr_cstr,
if (!child_valobj_sp)
{
valobj_sp->GetExpressionPath (var_expr_path_strm, false);
error.SetErrorStringWithFormat ("array index %i is not valid for \"(%s) %s\"",
error.SetErrorStringWithFormat ("array index %ld is not valid for \"(%s) %s\"",
child_index,
valobj_sp->GetTypeName().AsCString("<invalid type>"),
var_expr_path_strm.GetString().c_str());
@ -797,7 +797,7 @@ StackFrame::GetValueForVariableExpressionPath (const char *var_expr_cstr,
if (!child_valobj_sp)
{
valobj_sp->GetExpressionPath (var_expr_path_strm, false);
error.SetErrorStringWithFormat ("bitfield range %i-%i is not valid for \"(%s) %s\"",
error.SetErrorStringWithFormat ("bitfield range %ld-%ld is not valid for \"(%s) %s\"",
child_index, child_index,
valobj_sp->GetTypeName().AsCString("<invalid type>"),
var_expr_path_strm.GetString().c_str());
@ -818,7 +818,7 @@ StackFrame::GetValueForVariableExpressionPath (const char *var_expr_cstr,
else if (child_index >= synthetic->GetNumChildren() /* synthetic does not have that many values */)
{
valobj_sp->GetExpressionPath (var_expr_path_strm, false);
error.SetErrorStringWithFormat ("array index %i is not valid for \"(%s) %s\"",
error.SetErrorStringWithFormat ("array index %ld is not valid for \"(%s) %s\"",
child_index,
valobj_sp->GetTypeName().AsCString("<invalid type>"),
var_expr_path_strm.GetString().c_str());
@ -829,7 +829,7 @@ StackFrame::GetValueForVariableExpressionPath (const char *var_expr_cstr,
if (!child_valobj_sp)
{
valobj_sp->GetExpressionPath (var_expr_path_strm, false);
error.SetErrorStringWithFormat ("array index %i is not valid for \"(%s) %s\"",
error.SetErrorStringWithFormat ("array index %ld is not valid for \"(%s) %s\"",
child_index,
valobj_sp->GetTypeName().AsCString("<invalid type>"),
var_expr_path_strm.GetString().c_str());
@ -930,7 +930,7 @@ StackFrame::GetValueForVariableExpressionPath (const char *var_expr_cstr,
if (!child_valobj_sp)
{
valobj_sp->GetExpressionPath (var_expr_path_strm, false);
error.SetErrorStringWithFormat ("bitfield range %i-%i is not valid for \"(%s) %s\"",
error.SetErrorStringWithFormat ("bitfield range %ld-%ld is not valid for \"(%s) %s\"",
child_index, final_index,
valobj_sp->GetTypeName().AsCString("<invalid type>"),
var_expr_path_strm.GetString().c_str());

View File

@ -769,7 +769,8 @@ Target::ReadMemory (const Address& addr,
if (resolved_addr.GetModule() && resolved_addr.GetModule()->GetFileSpec())
error.SetErrorStringWithFormat("%s[0x%llx] can't be resolved, %s in not currently loaded.\n",
resolved_addr.GetModule()->GetFileSpec().GetFilename().AsCString(),
resolved_addr.GetFileAddress());
resolved_addr.GetFileAddress(),
resolved_addr.GetModule()->GetFileSpec().GetFilename().AsCString());
else
error.SetErrorStringWithFormat("0x%llx can't be resolved.\n", resolved_addr.GetFileAddress());
}