From 5a19c50da319f8bd830fdf4b8477ee912cea9b31 Mon Sep 17 00:00:00 2001
From: BogDan Vatra <bogdan@kde.org>
Date: Sat, 10 Jan 2015 10:49:26 +0200
Subject: [PATCH 05/11] Use snprintf insted of sprintf_s.
There is no sprintf_s in the standard, but there is a snprintf which does the smae thing.
---
source/gui/IGUIObject.cpp | 2 +-
source/gui/scripting/ScriptFunctions.cpp | 16 ++++++++--------
source/network/NetServer.cpp | 2 +-
source/ps/CLogger.cpp | 6 +++---
source/ps/GUID.cpp | 2 +-
source/ps/Profile.cpp | 22 +++++++++++-----------
source/ps/UserReport.cpp | 2 +-
source/ps/XML/XeroXMB.cpp | 2 +-
source/renderer/Renderer.cpp | 22 +++++++++++-----------
.../simulation2/serialization/DebugSerializer.cpp | 2 +-
.../atlas/GameInterface/MessagePasserImpl.cpp | 2 +-
11 files changed, 40 insertions(+), 40 deletions(-)
diff --git a/source/gui/IGUIObject.cpp b/source/gui/IGUIObject.cpp
index d32cb28..54146f9 100644
a
|
b
|
void IGUIObject::RegisterScriptHandler(const CStr& Action, const CStr& Code, CGU
|
433 | 433 | // Generate a unique name |
434 | 434 | static int x=0; |
435 | 435 | char buf[64]; |
436 | | sprintf_s(buf, ARRAY_SIZE(buf), "__eventhandler%d (%s)", x++, Action.c_str()); |
| 436 | snprintf(buf, ARRAY_SIZE(buf), "__eventhandler%d (%s)", x++, Action.c_str()); |
437 | 437 | |
438 | 438 | JS::RootedFunction func(cx, JS_CompileFunction(cx, globalObj, |
439 | 439 | buf, paramCount, paramNames, Code.c_str(), Code.length(), CodeName.c_str(), 0)); |
diff --git a/source/gui/scripting/ScriptFunctions.cpp b/source/gui/scripting/ScriptFunctions.cpp
index 1f7f309..86863bd 100644
a
|
b
|
std::wstring GetBuildTimestamp(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), i
|
792 | 792 | UDate dateTime = g_L10n.ParseDateTime(__DATE__ " " __TIME__, "MMM d yyyy HH:mm:ss", Locale::getUS()); |
793 | 793 | std::string dateTimeString = g_L10n.LocalizeDateTime(dateTime, L10n::DateTime, SimpleDateFormat::DATE_TIME); |
794 | 794 | char svnRevision[32]; |
795 | | sprintf_s(svnRevision, ARRAY_SIZE(svnRevision), "%ls", svn_revision); |
| 795 | snprintf(svnRevision, ARRAY_SIZE(svnRevision), "%ls", svn_revision); |
796 | 796 | if (strcmp(svnRevision, "custom build") == 0) |
797 | 797 | { |
798 | 798 | // Translation: First item is a date and time, item between parenthesis is the Subversion revision number of the current build. |
799 | | sprintf_s(buf, ARRAY_SIZE(buf), g_L10n.Translate("%s (custom build)").c_str(), dateTimeString.c_str()); |
| 799 | snprintf(buf, ARRAY_SIZE(buf), g_L10n.Translate("%s (custom build)").c_str(), dateTimeString.c_str()); |
800 | 800 | } |
801 | 801 | else |
802 | 802 | { |
803 | 803 | // Translation: First item is a date and time, item between parenthesis is the Subversion revision number of the current build. |
804 | | sprintf_s(buf, ARRAY_SIZE(buf), g_L10n.Translate("%s (%ls)").c_str(), dateTimeString.c_str(), svn_revision); |
| 804 | snprintf(buf, ARRAY_SIZE(buf), g_L10n.Translate("%s (%ls)").c_str(), dateTimeString.c_str(), svn_revision); |
805 | 805 | } |
806 | 806 | } |
807 | 807 | else if (mode == 0) // Date. |
808 | 808 | { |
809 | 809 | UDate dateTime = g_L10n.ParseDateTime(__DATE__, "MMM d yyyy", Locale::getUS()); |
810 | 810 | std::string dateTimeString = g_L10n.LocalizeDateTime(dateTime, L10n::Date, SimpleDateFormat::MEDIUM); |
811 | | sprintf_s(buf, ARRAY_SIZE(buf), "%s", dateTimeString.c_str()); |
| 811 | snprintf(buf, ARRAY_SIZE(buf), "%s", dateTimeString.c_str()); |
812 | 812 | } |
813 | 813 | else if (mode == 1) // Time. |
814 | 814 | { |
815 | 815 | UDate dateTime = g_L10n.ParseDateTime(__TIME__, "HH:mm:ss", Locale::getUS()); |
816 | 816 | std::string dateTimeString = g_L10n.LocalizeDateTime(dateTime, L10n::Time, SimpleDateFormat::MEDIUM); |
817 | | sprintf_s(buf, ARRAY_SIZE(buf), "%s", dateTimeString.c_str()); |
| 817 | snprintf(buf, ARRAY_SIZE(buf), "%s", dateTimeString.c_str()); |
818 | 818 | } |
819 | 819 | else if (mode == 2) // Revision. |
820 | 820 | { |
821 | 821 | char svnRevision[32]; |
822 | | sprintf_s(svnRevision, ARRAY_SIZE(svnRevision), "%ls", svn_revision); |
| 822 | snprintf(svnRevision, ARRAY_SIZE(svnRevision), "%ls", svn_revision); |
823 | 823 | if (strcmp(svnRevision, "custom build") == 0) |
824 | 824 | { |
825 | | sprintf_s(buf, ARRAY_SIZE(buf), "%s", g_L10n.Translate("custom build").c_str()); |
| 825 | snprintf(buf, ARRAY_SIZE(buf), "%s", g_L10n.Translate("custom build").c_str()); |
826 | 826 | } |
827 | 827 | else |
828 | 828 | { |
829 | | sprintf_s(buf, ARRAY_SIZE(buf), "%ls", svn_revision); |
| 829 | snprintf(buf, ARRAY_SIZE(buf), "%ls", svn_revision); |
830 | 830 | } |
831 | 831 | } |
832 | 832 | |
diff --git a/source/network/NetServer.cpp b/source/network/NetServer.cpp
index bcf904d..f119703 100644
a
|
b
|
void* CNetServerWorker::SetupUPnP(void*)
|
205 | 205 | { |
206 | 206 | // Values we want to set. |
207 | 207 | char psPort[6]; |
208 | | sprintf_s(psPort, ARRAY_SIZE(psPort), "%d", PS_DEFAULT_PORT); |
| 208 | snprintf(psPort, ARRAY_SIZE(psPort), "%d", PS_DEFAULT_PORT); |
209 | 209 | const char* leaseDuration = "0"; // Indefinite/permanent lease duration. |
210 | 210 | const char* description = "0AD Multiplayer"; |
211 | 211 | const char* protocall = "UDP"; |
diff --git a/source/ps/CLogger.cpp b/source/ps/CLogger.cpp
index 1a68943..acfacbc 100644
a
|
b
|
void CLogger::Init()
|
116 | 116 | CLogger::~CLogger() |
117 | 117 | { |
118 | 118 | char buffer[128]; |
119 | | sprintf_s(buffer, ARRAY_SIZE(buffer), " with %d message(s), %d error(s) and %d warning(s).", m_NumberOfMessages,m_NumberOfErrors,m_NumberOfWarnings); |
| 119 | snprintf(buffer, ARRAY_SIZE(buffer), " with %d message(s), %d error(s) and %d warning(s).", m_NumberOfMessages,m_NumberOfErrors,m_NumberOfWarnings); |
120 | 120 | |
121 | 121 | time_t t = time(NULL); |
122 | 122 | struct tm* now = localtime(&t); |
123 | 123 | char currentDate[17]; |
124 | | sprintf_s(currentDate, ARRAY_SIZE(currentDate), "%04d-%02d-%02d", 1900+now->tm_year, 1+now->tm_mon, now->tm_mday); |
| 124 | snprintf(currentDate, ARRAY_SIZE(currentDate), "%04d-%02d-%02d", 1900+now->tm_year, 1+now->tm_mon, now->tm_mday); |
125 | 125 | char currentTime[10]; |
126 | | sprintf_s(currentTime, ARRAY_SIZE(currentTime), "%02d:%02d:%02d", now->tm_hour, now->tm_min, now->tm_sec); |
| 126 | snprintf(currentTime, ARRAY_SIZE(currentTime), "%02d:%02d:%02d", now->tm_hour, now->tm_min, now->tm_sec); |
127 | 127 | |
128 | 128 | //Write closing text |
129 | 129 | |
diff --git a/source/ps/GUID.cpp b/source/ps/GUID.cpp
index cf8807e..399d95a 100644
a
|
b
|
CStr ps_generate_guid(void)
|
33 | 33 | u32 r = 0; |
34 | 34 | sys_generate_random_bytes((u8*)&r, sizeof(r)); |
35 | 35 | char buf[32]; |
36 | | sprintf_s(buf, ARRAY_SIZE(buf), "%08X", r); |
| 36 | snprintf(buf, ARRAY_SIZE(buf), "%08X", r); |
37 | 37 | guid += buf; |
38 | 38 | } |
39 | 39 | |
diff --git a/source/ps/Profile.cpp b/source/ps/Profile.cpp
index 7aa3f43..9823761 100644
a
|
b
|
CStr CProfileNodeTable::GetName()
|
116 | 116 | CStr CProfileNodeTable::GetTitle() |
117 | 117 | { |
118 | 118 | char buf[512]; |
119 | | sprintf_s(buf, ARRAY_SIZE(buf), "Profiling Information for: %s (Time in node: %.3f msec/frame)", node->GetName(), node->GetFrameTime() * 1000.0f ); |
| 119 | snprintf(buf, ARRAY_SIZE(buf), "Profiling Information for: %s (Time in node: %.3f msec/frame)", node->GetName(), node->GetFrameTime() * 1000.0f ); |
120 | 120 | return buf; |
121 | 121 | } |
122 | 122 | |
… |
… |
CStr CProfileNodeTable::GetCellText(size_t row, size_t col)
|
186 | 186 | } |
187 | 187 | |
188 | 188 | if (col == 2) |
189 | | sprintf_s(buf, ARRAY_SIZE(buf), "%.3f", unlogged_time_frame * 1000.0f); |
| 189 | snprintf(buf, ARRAY_SIZE(buf), "%.3f", unlogged_time_frame * 1000.0f); |
190 | 190 | else if (col == 3) |
191 | | sprintf_s(buf, ARRAY_SIZE(buf), "%.1f", unlogged_mallocs_frame); |
| 191 | snprintf(buf, ARRAY_SIZE(buf), "%.1f", unlogged_mallocs_frame); |
192 | 192 | else if (col == 5) |
193 | | sprintf_s(buf, ARRAY_SIZE(buf), "%.3f", unlogged_time_turn * 1000.f); |
| 193 | snprintf(buf, ARRAY_SIZE(buf), "%.3f", unlogged_time_turn * 1000.f); |
194 | 194 | else if (col == 6) |
195 | | sprintf_s(buf, ARRAY_SIZE(buf), "%.1f", unlogged_mallocs_turn); |
| 195 | snprintf(buf, ARRAY_SIZE(buf), "%.1f", unlogged_mallocs_turn); |
196 | 196 | |
197 | 197 | return CStr(buf); |
198 | 198 | } |
… |
… |
CStr CProfileNodeTable::GetCellText(size_t row, size_t col)
|
204 | 204 | return child->GetName(); |
205 | 205 | |
206 | 206 | case 1: |
207 | | sprintf_s(buf, ARRAY_SIZE(buf), "%.1f", child->GetFrameCalls()); |
| 207 | snprintf(buf, ARRAY_SIZE(buf), "%.1f", child->GetFrameCalls()); |
208 | 208 | break; |
209 | 209 | case 2: |
210 | | sprintf_s(buf, ARRAY_SIZE(buf), "%.3f", child->GetFrameTime() * 1000.0f); |
| 210 | snprintf(buf, ARRAY_SIZE(buf), "%.3f", child->GetFrameTime() * 1000.0f); |
211 | 211 | break; |
212 | 212 | case 3: |
213 | | sprintf_s(buf, ARRAY_SIZE(buf), "%.1f", child->GetFrameMallocs()); |
| 213 | snprintf(buf, ARRAY_SIZE(buf), "%.1f", child->GetFrameMallocs()); |
214 | 214 | break; |
215 | 215 | case 4: |
216 | | sprintf_s(buf, ARRAY_SIZE(buf), "%.1f", child->GetTurnCalls()); |
| 216 | snprintf(buf, ARRAY_SIZE(buf), "%.1f", child->GetTurnCalls()); |
217 | 217 | break; |
218 | 218 | case 5: |
219 | | sprintf_s(buf, ARRAY_SIZE(buf), "%.3f", child->GetTurnTime() * 1000.0f); |
| 219 | snprintf(buf, ARRAY_SIZE(buf), "%.3f", child->GetTurnTime() * 1000.0f); |
220 | 220 | break; |
221 | 221 | case 6: |
222 | | sprintf_s(buf, ARRAY_SIZE(buf), "%.1f", child->GetTurnMallocs()); |
| 222 | snprintf(buf, ARRAY_SIZE(buf), "%.1f", child->GetTurnMallocs()); |
223 | 223 | break; |
224 | 224 | } |
225 | 225 | return CStr(buf); |
diff --git a/source/ps/UserReport.cpp b/source/ps/UserReport.cpp
index 755542d..27d2b7b 100644
a
|
b
|
std::string CUserReporter::LoadUserID()
|
533 | 533 | for (size_t i = 0; i < ARRAY_SIZE(bytes); ++i) |
534 | 534 | { |
535 | 535 | char hex[3]; |
536 | | sprintf_s(hex, ARRAY_SIZE(hex), "%02x", (unsigned int)bytes[i]); |
| 536 | snprintf(hex, ARRAY_SIZE(hex), "%02x", (unsigned int)bytes[i]); |
537 | 537 | userID += hex; |
538 | 538 | } |
539 | 539 | |
diff --git a/source/ps/XML/XeroXMB.cpp b/source/ps/XML/XeroXMB.cpp
index 16ee3e7..35b4712 100644
a
|
b
|
bool XMBFile::Initialise(const char* FileData)
|
34 | 34 | { |
35 | 35 | m_Pointer = FileData; |
36 | 36 | char Header[5] = { 0 }; |
37 | | strncpy_s(Header, 5, m_Pointer, 4); |
| 37 | strncpy(Header, m_Pointer, 4); |
38 | 38 | m_Pointer += 4; |
39 | 39 | // (c.f. @return documentation of this function) |
40 | 40 | if(!strcmp(Header, UnfinishedHeaderMagicStr)) |
diff --git a/source/renderer/Renderer.cpp b/source/renderer/Renderer.cpp
index 404d90a..0808792 100644
a
|
b
|
CStr CRendererStatsTable::GetCellText(size_t row, size_t col)
|
169 | 169 | case Row_DrawCalls: |
170 | 170 | if (col == 0) |
171 | 171 | return "# draw calls"; |
172 | | sprintf_s(buf, sizeof(buf), "%lu", (unsigned long)Stats.m_DrawCalls); |
| 172 | snprintf(buf, sizeof(buf), "%lu", (unsigned long)Stats.m_DrawCalls); |
173 | 173 | return buf; |
174 | 174 | |
175 | 175 | case Row_TerrainTris: |
176 | 176 | if (col == 0) |
177 | 177 | return "# terrain tris"; |
178 | | sprintf_s(buf, sizeof(buf), "%lu", (unsigned long)Stats.m_TerrainTris); |
| 178 | snprintf(buf, sizeof(buf), "%lu", (unsigned long)Stats.m_TerrainTris); |
179 | 179 | return buf; |
180 | 180 | |
181 | 181 | case Row_WaterTris: |
182 | 182 | if (col == 0) |
183 | 183 | return "# water tris"; |
184 | | sprintf_s(buf, sizeof(buf), "%lu", (unsigned long)Stats.m_WaterTris); |
| 184 | snprintf(buf, sizeof(buf), "%lu", (unsigned long)Stats.m_WaterTris); |
185 | 185 | return buf; |
186 | 186 | |
187 | 187 | case Row_ModelTris: |
188 | 188 | if (col == 0) |
189 | 189 | return "# model tris"; |
190 | | sprintf_s(buf, sizeof(buf), "%lu", (unsigned long)Stats.m_ModelTris); |
| 190 | snprintf(buf, sizeof(buf), "%lu", (unsigned long)Stats.m_ModelTris); |
191 | 191 | return buf; |
192 | 192 | |
193 | 193 | case Row_OverlayTris: |
194 | 194 | if (col == 0) |
195 | 195 | return "# overlay tris"; |
196 | | sprintf_s(buf, sizeof(buf), "%lu", (unsigned long)Stats.m_OverlayTris); |
| 196 | snprintf(buf, sizeof(buf), "%lu", (unsigned long)Stats.m_OverlayTris); |
197 | 197 | return buf; |
198 | 198 | |
199 | 199 | case Row_BlendSplats: |
200 | 200 | if (col == 0) |
201 | 201 | return "# blend splats"; |
202 | | sprintf_s(buf, sizeof(buf), "%lu", (unsigned long)Stats.m_BlendSplats); |
| 202 | snprintf(buf, sizeof(buf), "%lu", (unsigned long)Stats.m_BlendSplats); |
203 | 203 | return buf; |
204 | 204 | |
205 | 205 | case Row_Particles: |
206 | 206 | if (col == 0) |
207 | 207 | return "# particles"; |
208 | | sprintf_s(buf, sizeof(buf), "%lu", (unsigned long)Stats.m_Particles); |
| 208 | snprintf(buf, sizeof(buf), "%lu", (unsigned long)Stats.m_Particles); |
209 | 209 | return buf; |
210 | 210 | |
211 | 211 | case Row_VBReserved: |
212 | 212 | if (col == 0) |
213 | 213 | return "VB reserved"; |
214 | | sprintf_s(buf, sizeof(buf), "%lu kB", (unsigned long)g_VBMan.GetBytesReserved() / 1024); |
| 214 | snprintf(buf, sizeof(buf), "%lu kB", (unsigned long)g_VBMan.GetBytesReserved() / 1024); |
215 | 215 | return buf; |
216 | 216 | |
217 | 217 | case Row_VBAllocated: |
218 | 218 | if (col == 0) |
219 | 219 | return "VB allocated"; |
220 | | sprintf_s(buf, sizeof(buf), "%lu kB", (unsigned long)g_VBMan.GetBytesAllocated() / 1024); |
| 220 | snprintf(buf, sizeof(buf), "%lu kB", (unsigned long)g_VBMan.GetBytesAllocated() / 1024); |
221 | 221 | return buf; |
222 | 222 | |
223 | 223 | case Row_TextureMemory: |
224 | 224 | if (col == 0) |
225 | 225 | return "textures uploaded"; |
226 | | sprintf_s(buf, sizeof(buf), "%lu kB", (unsigned long)g_Renderer.GetTextureManager().GetBytesUploaded() / 1024); |
| 226 | snprintf(buf, sizeof(buf), "%lu kB", (unsigned long)g_Renderer.GetTextureManager().GetBytesUploaded() / 1024); |
227 | 227 | return buf; |
228 | 228 | |
229 | 229 | case Row_ShadersLoaded: |
230 | 230 | if (col == 0) |
231 | 231 | return "shader effects loaded"; |
232 | | sprintf_s(buf, sizeof(buf), "%lu", (unsigned long)g_Renderer.GetShaderManager().GetNumEffectsLoaded()); |
| 232 | snprintf(buf, sizeof(buf), "%lu", (unsigned long)g_Renderer.GetShaderManager().GetNumEffectsLoaded()); |
233 | 233 | return buf; |
234 | 234 | |
235 | 235 | default: |
diff --git a/source/simulation2/serialization/DebugSerializer.cpp b/source/simulation2/serialization/DebugSerializer.cpp
index 07cdd76..16de1ee 100644
a
|
b
|
void CDebugSerializer::PutRaw(const char* name, const u8* data, size_t len)
|
161 | 161 | char buf[4]; |
162 | 162 | for (size_t i = 0; i < len; ++i) |
163 | 163 | { |
164 | | sprintf_s(buf, ARRAY_SIZE(buf), " %02x", (unsigned int)data[i]); |
| 164 | snprintf(buf, ARRAY_SIZE(buf), " %02x", (unsigned int)data[i]); |
165 | 165 | m_Stream << buf; |
166 | 166 | } |
167 | 167 | |
diff --git a/source/tools/atlas/GameInterface/MessagePasserImpl.cpp b/source/tools/atlas/GameInterface/MessagePasserImpl.cpp
index 7f324a0..ae32eab 100644
a
|
b
|
MessagePasserImpl::MessagePasserImpl()
|
36 | 36 | while (tries++ < 16) // some arbitrary cut-off point to avoid infinite loops |
37 | 37 | { |
38 | 38 | static char name[64]; |
39 | | sprintf_s(name, ARRAY_SIZE(name), "/wfg-atlas-msgpass-%d-%d", |
| 39 | snprintf(name, ARRAY_SIZE(name), "/wfg-atlas-msgpass-%d-%d", |
40 | 40 | (int)rand(1, 1000), (int)(time(0)%1000)); |
41 | 41 | sem_t* sem = sem_open(name, O_CREAT | O_EXCL, 0700, 0); |
42 | 42 | |