aboutsummaryrefslogtreecommitdiffstats
path: root/fastos
diff options
context:
space:
mode:
authorTor Egge <Tor.Egge@online.no>2023-01-31 12:46:10 +0100
committerTor Egge <Tor.Egge@online.no>2023-01-31 12:46:10 +0100
commit8dca74eb0879fe0e530c783d74a355747422aeec (patch)
tree1558b0d553400bf7a4e14ec01e82358ba8cfd1fd /fastos
parent82e48e07e3d93521dfc53993a30d7f25ded4a440 (diff)
Use snprintf instead of sprintf.
Diffstat (limited to 'fastos')
-rw-r--r--fastos/src/tests/thread_joinwait_test.cpp2
-rw-r--r--fastos/src/tests/threadtest.cpp5
2 files changed, 4 insertions, 3 deletions
diff --git a/fastos/src/tests/thread_joinwait_test.cpp b/fastos/src/tests/thread_joinwait_test.cpp
index a26501fef01..6c7e8a7dc3c 100644
--- a/fastos/src/tests/thread_joinwait_test.cpp
+++ b/fastos/src/tests/thread_joinwait_test.cpp
@@ -14,7 +14,7 @@ class Thread_JoinWait_Test : public ThreadTestBase
char testName[300];
- sprintf(testName, "Single Thread Join Wait Multiple Test %d", variant);
+ snprintf(testName, sizeof(testName), "Single Thread Join Wait Multiple Test %d", variant);
TestHeader(testName);
FastOS_ThreadPool pool;
diff --git a/fastos/src/tests/threadtest.cpp b/fastos/src/tests/threadtest.cpp
index 34723e4edce..563b41ac229 100644
--- a/fastos/src/tests/threadtest.cpp
+++ b/fastos/src/tests/threadtest.cpp
@@ -18,6 +18,7 @@ class ThreadTest : public ThreadTestBase
void TooManyThreadsTest ()
{
TestHeader("Too Many Threads Test");
+ static constexpr size_t message_size = 100;
FastOS_ThreadPool *pool = new FastOS_ThreadPool(MAX_THREADS);
@@ -27,11 +28,11 @@ class ThreadTest : public ThreadTestBase
for (i=0; i<MAX_THREADS+1; i++) {
jobs[i].code = WAIT_FOR_BREAK_FLAG;
- jobs[i].message = static_cast<char *>(malloc(100));
+ jobs[i].message = static_cast<char *>(malloc(message_size));
if (jobs[i].message == nullptr) {
abort(); // GCC may infer that a potentially null ptr is passed to sprintf
}
- sprintf(jobs[i].message, "Thread %d invocation", i+1);
+ snprintf(jobs[i].message, message_size, "Thread %d invocation", i+1);
}
for (i=0; i<MAX_THREADS+1; i++) {