Detect and fix printf signedness errors. Fixes #1086, #1087.

This was SVN commit r10846.
This commit is contained in:
Ykkrosh 2012-01-01 16:43:10 +00:00
parent cc405939c2
commit 0ec4242962
21 changed files with 51 additions and 41 deletions

View File

@ -125,24 +125,34 @@ function compare_format_type(ctype, functype, fmt, arg, loc) {
error('Illegal %hs used in printf-style function', loc());
if (functype == 'printf') {
if (t.match(/^[diouxXc]$/))
return (arg == 'int' || arg == 'unsigned int');
if (t.match(/^[dic]$/))
return (arg == 'int');
if (t.match(/^[ouxX]$/))
return (arg == 'unsigned int');
if (t.match(/^lc$/))
return (arg == 'int' || arg == 'unsigned int'); // spec says wint_t
if (t.match(/^l[diouxX]$/))
return (arg == 'long int' || arg == 'long unsigned int');
if (t.match(/^ll[diouxX]$/))
return (arg == 'long long int' || arg == 'long long unsigned int');
if (t.match(/^l[di]$/))
return (arg == 'long int');
if (t.match(/^l[ouxX]$/))
return (arg == 'long unsigned int');
if (t.match(/^ll[di]$/))
return (arg == 'long long int');
if (t.match(/^ll[ouxX]$/))
return (arg == 'long long unsigned int');
if (t.match(/^[fFeEgGaA]$/))
return (arg == 'double');
if (t.match(/^p$/))
return (arg.match(/\*$/));
// ...
} else if (functype == 'scanf') {
if (t.match(/^[dioux]$/))
if (t.match(/^[di]$/))
return (arg == 'int*');
if (t.match(/^l[diouxX]$/))
if (t.match(/^[ouxX]$/))
return (arg == 'unsigned int*');
if (t.match(/^l[di]$/))
return (arg == 'long int*');
if (t.match(/^l[ouxX]$/))
return (arg == 'long unsigned int*');
if (t.match(/^z[diouxX]$/))
return (arg == 'long unsigned int*'); // spec says size_t*
if (t.match(/^[c[]$/))

View File

@ -1060,7 +1060,7 @@ void CGUI::LoadXmlFile(const VfsPath& Filename, boost::unordered_set<VfsPath>& P
}
catch (PSERROR_GUI& e)
{
LOGERROR(L"Errors loading GUI file %ls (%d)", Filename.string().c_str(), e.getCode());
LOGERROR(L"Errors loading GUI file %ls (%u)", Filename.string().c_str(), e.getCode());
return;
}
}

View File

@ -391,7 +391,7 @@ void ogl_WarnIfError()
}
if(error_enountered)
debug_printf(L"OpenGL error(s) occurred: %04x\n", (int)first_error);
debug_printf(L"OpenGL error(s) occurred: %04x\n", (unsigned int)first_error);
}
#endif
@ -430,7 +430,7 @@ bool ogl_SquelchError(GLenum err_to_ignore)
}
if(error_enountered)
debug_printf(L"OpenGL error(s) occurred: %04x\n", (int)first_error);
debug_printf(L"OpenGL error(s) occurred: %04x\n", (unsigned int)first_error);
return error_ignored;
}

View File

@ -505,7 +505,7 @@ static Status OglTex_validate(const OglTex* ot)
static Status OglTex_to_string(const OglTex* ot, wchar_t* buf)
{
swprintf_s(buf, H_STRING_LEN, L"OglTex id=%d flags=%x", ot->id, ot->flags);
swprintf_s(buf, H_STRING_LEN, L"OglTex id=%u flags=%x", ot->id, (unsigned int)ot->flags);
return INFO::OK;
}

View File

@ -933,7 +933,7 @@ static Status SndData_validate(const SndData* sd)
static Status SndData_to_string(const SndData* sd, wchar_t* buf)
{
const wchar_t* type = (sd->type == SD_CLIP)? L"clip" : L"stream";
swprintf_s(buf, H_STRING_LEN, L"%ls; al_buf=%d", type, sd->al_buf);
swprintf_s(buf, H_STRING_LEN, L"%ls; al_buf=%u", type, sd->al_buf);
return INFO::OK;
}
@ -1309,7 +1309,7 @@ static Status VSrc_validate(const VSrc* vs)
static Status VSrc_to_string(const VSrc* vs, wchar_t* buf)
{
swprintf_s(buf, H_STRING_LEN, L"al_src = %d", vs->al_src);
swprintf_s(buf, H_STRING_LEN, L"al_src = %u", vs->al_src);
return INFO::OK;
}

View File

@ -85,7 +85,7 @@ wchar_t* StatusDescription(Status status, wchar_t* buf, size_t max_chars)
return buf;
}
swprintf_s(buf, max_chars, L"Unknown error (%lld, 0x%llX)", (long long)status, (long long)status);
swprintf_s(buf, max_chars, L"Unknown error (%lld, 0x%llX)", (long long)status, (unsigned long long)status);
return buf;
}

View File

@ -530,7 +530,7 @@ static const Characteristics* CharacteristicsFromDescriptor(Descriptor descripto
return &characteristics;
}
debug_printf(L"Unknown cache/TLB descriptor 0x%x\n", descriptor);
debug_printf(L"Unknown cache/TLB descriptor 0x%x\n", (unsigned int)descriptor);
return 0;
}

View File

@ -26,7 +26,7 @@ public:
{
char digeststr[MD5::DIGESTSIZE*2+1];
for (size_t i = 0; i < MD5::DIGESTSIZE; ++i)
sprintf_s(digeststr+2*i, 3, "%02x", digest[i]);
sprintf_s(digeststr+2*i, 3, "%02x", (unsigned int)digest[i]);
return digeststr;
}

View File

@ -266,7 +266,7 @@ bool CNetClient::HandleMessage(CNetMessage* message)
std::stringstream stream;
LOGMESSAGERENDER(L"Serializing game at turn %d for rejoining player", m_ClientTurnManager->GetCurrentTurn());
LOGMESSAGERENDER(L"Serializing game at turn %u for rejoining player", m_ClientTurnManager->GetCurrentTurn());
u32 turn = to_le32(m_ClientTurnManager->GetCurrentTurn());
stream.write((char*)&turn, sizeof(turn));
@ -306,7 +306,7 @@ void CNetClient::LoadFinished()
stream.read((char*)&turn, sizeof(turn));
turn = to_le32(turn);
LOGMESSAGE(L"Rejoining client deserializing state at turn %d\n", turn);
LOGMESSAGE(L"Rejoining client deserializing state at turn %u\n", turn);
bool ok = m_Game->GetSimulation2()->DeserializeState(stream);
ENSURE(ok);
@ -381,7 +381,7 @@ bool CNetClient::OnAuthenticate(void* context, CFsmEvent* event)
CAuthenticateResultMessage* message = (CAuthenticateResultMessage*)event->GetParamRef();
LOGMESSAGE(L"Net: Authentication result: host=%d, %ls", message->m_HostID, message->m_Message.c_str());
LOGMESSAGE(L"Net: Authentication result: host=%u, %ls", message->m_HostID, message->m_Message.c_str());
bool isRejoining = (message->m_Code == ARC_OK_REJOINING);

View File

@ -317,7 +317,7 @@ bool CNetServerWorker::RunStep()
// Report the client address
char hostname[256] = "(error)";
enet_address_get_host_ip(&event.peer->address, hostname, ARRAY_SIZE(hostname));
LOGMESSAGE(L"Net server: Received connection from %hs:%u", hostname, event.peer->address.port);
LOGMESSAGE(L"Net server: Received connection from %hs:%u", hostname, (unsigned int)event.peer->address.port);
// Set up a session object for this peer

View File

@ -112,7 +112,7 @@ void CNetClientSession::Poll()
// Report the server address
char hostname[256] = "(error)";
enet_address_get_host_ip(&event.peer->address, hostname, ARRAY_SIZE(hostname));
LOGMESSAGE(L"Net client: Connected to %hs:%u", hostname, event.peer->address.port);
LOGMESSAGE(L"Net client: Connected to %hs:%u", hostname, (unsigned int)event.peer->address.port);
m_Client.HandleConnect();

View File

@ -273,7 +273,7 @@ public:
for (size_t i = 0; ; ++i)
{
debug_printf(L"[%d]\n", client2B.GetCurrState());
debug_printf(L"[%u]\n", client2B.GetCurrState());
client2B.Poll();
if (client2B.GetCurrState() == NCS_PREGAME)
break;

View File

@ -252,7 +252,7 @@ private:
// Associate the frame number with the "frame" region
if (i == 0)
m_Storage.RecordAttributePrintf("%d", frame.num);
m_Storage.RecordAttributePrintf("%u", frame.num);
}
PopFrontFrame();
@ -404,7 +404,7 @@ private:
// Associate the frame number with the "frame" region
if (i == 0)
m_Storage.RecordAttributePrintf("%d", frame.num);
m_Storage.RecordAttributePrintf("%u", frame.num);
// Advance by the elapsed time to the next event
GLuint64 queryElapsed = 0;
@ -636,7 +636,7 @@ private:
m_Storage.Record(CProfiler2::ITEM_ENTER, lastTime, frame.events[i].id);
if (i == 0)
m_Storage.RecordAttributePrintf("%d", frame.num);
m_Storage.RecordAttributePrintf("%u", frame.num);
double elapsed = 0.0;
@ -659,7 +659,7 @@ private:
ENSURE(counter.size == 4);
GLuint value;
memcpy(&value, buf + counter.offset, counter.size);
m_Storage.RecordAttributePrintf("%s: %d", counter.name.c_str(), value);
m_Storage.RecordAttributePrintf("%s: %u", counter.name.c_str(), value);
}
else if (counter.type == INTEL_PERFQUERIES_TYPE_UNSIGNED_INT64)
{
@ -684,7 +684,7 @@ private:
GLuint value;
memcpy(&value, buf + counter.offset, counter.size);
ENSURE(value == 0 || value == 1);
m_Storage.RecordAttributePrintf("%s: %d", counter.name.c_str(), value);
m_Storage.RecordAttributePrintf("%s: %u", counter.name.c_str(), value);
}
else
{

View File

@ -166,7 +166,7 @@ void CReplayPlayer::Replay()
else if (type == "turn")
{
*m_Stream >> turn >> turnLength;
debug_printf(L"Turn %d (%d)... ", turn, turnLength);
debug_printf(L"Turn %u (%u)... ", turn, turnLength);
}
else if (type == "cmd")
{

View File

@ -533,7 +533,7 @@ std::string CUserReporter::LoadUserID()
for (size_t i = 0; i < ARRAY_SIZE(bytes); ++i)
{
char hex[3];
sprintf_s(hex, ARRAY_SIZE(hex), "%02x", bytes[i]);
sprintf_s(hex, ARRAY_SIZE(hex), "%02x", (unsigned int)bytes[i]);
userID += hex;
}

View File

@ -401,7 +401,7 @@ void ShadowMapInternals::CreateTexture()
if (status != GL_FRAMEBUFFER_COMPLETE_EXT)
{
LOGWARNING(L"Framebuffer object incomplete: %04d", status);
LOGWARNING(L"Framebuffer object incomplete: 0x%04X", status);
// Disable shadow rendering (but let the user try again if they want)
g_Renderer.m_Options.m_Shadows = false;

View File

@ -493,7 +493,7 @@ void CCmpPathfinder::ComputePath(entity_pos_t x0, entity_pos_t z0, const Goal& g
PROFILE2_ATTR("from: (%d, %d)", i0, j0);
PROFILE2_ATTR("to: (%d, %d)", state.iGoal, state.jGoal);
PROFILE2_ATTR("reached: (%d, %d)", state.iBest, state.jBest);
PROFILE2_ATTR("steps: %d", state.steps);
PROFILE2_ATTR("steps: %u", state.steps);
#if PATHFIND_STATS
printf("PATHFINDER: steps=%d avgo=%d proc=%d impc=%d impo=%d addo=%d\n", state.steps, state.sumOpenSize/state.steps, state.numProcessed, state.numImproveClosed, state.numImproveOpen, state.numAddToOpen);

View File

@ -526,7 +526,7 @@ public:
{
if (m_Queries.find(tag) == m_Queries.end())
{
LOGERROR(L"CCmpRangeManager: DestroyActiveQuery called with invalid tag %d", tag);
LOGERROR(L"CCmpRangeManager: DestroyActiveQuery called with invalid tag %u", tag);
return;
}
@ -538,7 +538,7 @@ public:
std::map<tag_t, Query>::iterator it = m_Queries.find(tag);
if (it == m_Queries.end())
{
LOGERROR(L"CCmpRangeManager: EnableActiveQuery called with invalid tag %d", tag);
LOGERROR(L"CCmpRangeManager: EnableActiveQuery called with invalid tag %u", tag);
return;
}
@ -551,7 +551,7 @@ public:
std::map<tag_t, Query>::iterator it = m_Queries.find(tag);
if (it == m_Queries.end())
{
LOGERROR(L"CCmpRangeManager: DisableActiveQuery called with invalid tag %d", tag);
LOGERROR(L"CCmpRangeManager: DisableActiveQuery called with invalid tag %u", tag);
return;
}
@ -594,7 +594,7 @@ public:
std::map<tag_t, Query>::iterator it = m_Queries.find(tag);
if (it == m_Queries.end())
{
LOGERROR(L"CCmpRangeManager: ResetActiveQuery called with invalid tag %d", tag);
LOGERROR(L"CCmpRangeManager: ResetActiveQuery called with invalid tag %u", tag);
return r;
}
@ -777,11 +777,11 @@ public:
{
// Min range must be non-negative
if (minRange < entity_pos_t::Zero())
LOGWARNING(L"CCmpRangeManager: Invalid min range %f in query for entity %d", minRange.ToDouble(), source);
LOGWARNING(L"CCmpRangeManager: Invalid min range %f in query for entity %u", minRange.ToDouble(), source);
// Max range must be non-negative, or else -1
if (maxRange < entity_pos_t::Zero() && maxRange != entity_pos_t::FromInt(-1))
LOGWARNING(L"CCmpRangeManager: Invalid max range %f in query for entity %d", maxRange.ToDouble(), source);
LOGWARNING(L"CCmpRangeManager: Invalid max range %f in query for entity %u", maxRange.ToDouble(), source);
Query q;
q.enabled = false;

View File

@ -709,7 +709,7 @@ void CCmpUnitMotion::PathResult(u32 ticket, const ICmpPathfinder::Path& path)
}
else
{
LOGWARNING(L"unexpected PathResult (%d %d %d)", GetEntityId(), m_State, m_PathState);
LOGWARNING(L"unexpected PathResult (%u %d %d)", GetEntityId(), m_State, m_PathState);
}
}

View File

@ -161,7 +161,7 @@ void CDebugSerializer::PutRaw(const char* name, const u8* data, size_t len)
char buf[4];
for (size_t i = 0; i < len; ++i)
{
sprintf_s(buf, ARRAY_SIZE(buf), " %02x", data[i]);
sprintf_s(buf, ARRAY_SIZE(buf), " %02x", (unsigned int)data[i]);
m_Stream << buf;
}

View File

@ -522,7 +522,7 @@ public:
debug_printf(L"# size = %d\n", (int)str.str().length());
debug_printf(L"# hash = ");
for (size_t i = 0; i < hash.size(); ++i)
debug_printf(L"%02x", (u8)hash[i]);
debug_printf(L"%02x", (unsigned int)(u8)hash[i]);
debug_printf(L"\n");
}