Skip to content

Commit

Permalink
cxbe: Fix sprintf compiler warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
abaire authored and mborgerson committed Jul 5, 2023
1 parent d6f0f3a commit 2827db5
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 9 deletions.
8 changes: 4 additions & 4 deletions tools/cxbe/Exe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ Exe::Exe(const char *x_szFilename)
if(fread(&m_SectionHeader[v], sizeof(SectionHeader), 1, ExeFile) != 1)
{
char buffer[255];
sprintf(buffer, "Could not read PE section header %d (%Xh)", v, v);
snprintf(buffer, sizeof(buffer), "Could not read PE section header %d (%Xh)", v, v);
SetError(buffer, true);
goto cleanup;
}
Expand Down Expand Up @@ -148,7 +148,7 @@ Exe::Exe(const char *x_szFilename)
if(fread(m_bzSection[v], raw_size, 1, ExeFile) != 1)
{
char buffer[255];
sprintf(buffer, "Could not read PE section %d (%Xh)", v, v);
snprintf(buffer, sizeof(buffer), "Could not read PE section %d (%Xh)", v, v);
SetError(buffer, true);
goto cleanup;
}
Expand Down Expand Up @@ -267,7 +267,7 @@ void Exe::Export(const char *x_szExeFilename)
if(fwrite(&m_SectionHeader[v], sizeof(SectionHeader), 1, ExeFile) != 1)
{
char buffer[255];
sprintf(buffer, "Could not write PE section header %d (%Xh)", v, v);
snprintf(buffer, sizeof(buffer), "Could not write PE section header %d (%Xh)", v, v);
SetError(buffer, false);
goto cleanup;
}
Expand Down Expand Up @@ -298,7 +298,7 @@ void Exe::Export(const char *x_szExeFilename)
if(fwrite(m_bzSection[v], RawSize, 1, ExeFile) != 1)
{
char buffer[255];
sprintf(buffer, "Could not write PE section %d (%Xh)", v, v);
snprintf(buffer, sizeof(buffer), "Could not write PE section %d (%Xh)", v, v);
SetError(buffer, false);
goto cleanup;
}
Expand Down
32 changes: 27 additions & 5 deletions tools/cxbe/Xbe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,11 @@ Xbe::Xbe(const char *x_szFilename)

if(fread(&m_SectionHeader[v], sizeof(*m_SectionHeader), 1, XbeFile) != 1)
{
sprintf(szBuffer, "Unexpected end of file while reading Xbe Section Header %d (%Xh)", v, v);
snprintf(szBuffer,
sizeof(szBuffer),
"Unexpected end of file while reading Xbe Section Header %d (%Xh)",
v,
v);
SetError(szBuffer, true);
goto cleanup;
}
Expand Down Expand Up @@ -171,7 +175,11 @@ Xbe::Xbe(const char *x_szFilename)

if(fread(&m_LibraryVersion[v], sizeof(*m_LibraryVersion), 1, XbeFile) != 1)
{
sprintf(szBuffer, "Unexpected end of file while reading Xbe Library Version %d (%Xh)", v, v);
snprintf(szBuffer,
sizeof(szBuffer),
"Unexpected end of file while reading Xbe Library Version %d (%Xh)",
v,
v);
SetError(szBuffer, true);
goto cleanup;
}
Expand Down Expand Up @@ -253,7 +261,12 @@ Xbe::Xbe(const char *x_szFilename)

if(fread(m_bzSection[v], RawSize, 1, XbeFile) != 1)
{
sprintf(szBuffer, "Unexpected end of file while reading Xbe Section %d (%Xh) (%s)", v, v, m_szSectionName[v]);
snprintf(szBuffer,
sizeof(szBuffer),
"Unexpected end of file while reading Xbe Section %d (%Xh) (%s)",
v,
v,
m_szSectionName[v]);
SetError(szBuffer, true);
goto cleanup;
}
Expand Down Expand Up @@ -969,7 +982,11 @@ void Xbe::Export(const char *x_szXbeFilename)

if(fwrite(&m_SectionHeader[v], sizeof(*m_SectionHeader), 1, XbeFile) != 1)
{
sprintf(szBuffer, "Unexpected write error while writing Xbe Section %d (%Xh)", v, v);
snprintf(szBuffer,
sizeof(szBuffer),
"Unexpected write error while writing Xbe Section %d (%Xh)",
v,
v);
SetError(szBuffer, false);
goto cleanup;
}
Expand Down Expand Up @@ -999,7 +1016,12 @@ void Xbe::Export(const char *x_szXbeFilename)

if(fwrite(m_bzSection[v], RawSize, 1, XbeFile) != 1)
{
sprintf(szBuffer, "Unexpected write error while writing Xbe Section %d (%Xh) (%s)", v, v, m_szSectionName[v]);
snprintf(szBuffer,
sizeof(szBuffer),
"Unexpected write error while writing Xbe Section %d (%Xh) (%s)",
v,
v,
m_szSectionName[v]);
SetError(szBuffer, false);
goto cleanup;
}
Expand Down

0 comments on commit 2827db5

Please sign in to comment.