From 2827db59e0de0f03ee485a26cbb1ced0971ab881 Mon Sep 17 00:00:00 2001 From: Erik Abair Date: Sat, 24 Jun 2023 17:59:25 -0700 Subject: [PATCH] cxbe: Fix sprintf compiler warnings --- tools/cxbe/Exe.cpp | 8 ++++---- tools/cxbe/Xbe.cpp | 32 +++++++++++++++++++++++++++----- 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/tools/cxbe/Exe.cpp b/tools/cxbe/Exe.cpp index 221f3df71..35be5b8a2 100644 --- a/tools/cxbe/Exe.cpp +++ b/tools/cxbe/Exe.cpp @@ -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; } @@ -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; } @@ -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; } @@ -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; } diff --git a/tools/cxbe/Xbe.cpp b/tools/cxbe/Xbe.cpp index be288cf75..c9102052c 100644 --- a/tools/cxbe/Xbe.cpp +++ b/tools/cxbe/Xbe.cpp @@ -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; } @@ -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; } @@ -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; } @@ -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; } @@ -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; }