diff --git a/core/detectors/trd/CbmTrdRadiator.cxx b/core/detectors/trd/CbmTrdRadiator.cxx
index d69291295adfd52cac9a636eaeb20a60b0c79a8f..f4d926690e0a7b4bfa104b2a61fe472080ff43c8 100644
--- a/core/detectors/trd/CbmTrdRadiator.cxx
+++ b/core/detectors/trd/CbmTrdRadiator.cxx
@@ -156,7 +156,8 @@ void CbmTrdRadiator::CreateHistograms()
   Float_t SpLower = 1.0 - 0.5 * fSpBinWidth;
   Float_t SpUpper = SpLower + (Float_t) fSpRange;
 
-  Char_t name[50];
+  size_t buf_size = 50;
+  Char_t name[buf_size];
 
   if (fSpectrum) delete fSpectrum;
   fSpectrum = new TH1D("fSpectrum", "TR spectrum", fSpNBins, SpLower, SpUpper);
@@ -171,7 +172,7 @@ void CbmTrdRadiator::CreateHistograms()
   fDetSpectrumA = new TH1D("fDetSpectrumA", "TR spectrum absorbed in detector", fSpNBins, SpLower, SpUpper);
 
   for (Int_t i = 0; i < fNMom; i++) {
-    sprintf(name, "fFinal%d", i + 1);
+    snprintf(name, buf_size - 1, "fFinal%d", i + 1);
     //LOG(info) <<"name : "<<name;
     if (fFinal[i]) delete fFinal[i];
     fFinal[i] = new TH1D(name, name, fSpNBins, SpLower, SpUpper);
diff --git a/core/eventdisplay/CbmRecoTracks.cxx b/core/eventdisplay/CbmRecoTracks.cxx
index 2df8182009497fda4f5240c19f2cdd608c4054bb..f3b3f169271fc2737d4d561e3835cee3059c3919 100644
--- a/core/eventdisplay/CbmRecoTracks.cxx
+++ b/core/eventdisplay/CbmRecoTracks.cxx
@@ -278,8 +278,9 @@ void CbmRecoTracks::Reset()
 
 TEveTrackList* CbmRecoTracks::GetTrGroup(TParticle* P)
 {
-  char name_buf[128];
-  sprintf(name_buf, "reco_%s", P->GetName());
+  size_t buf_size = 128;
+  char name_buf[buf_size];
+  snprintf(name_buf, buf_size - 1, "reco_%s", P->GetName());
   fTrList = 0;
   for (Int_t i = 0; i < fEveTrList->GetEntriesFast(); i++) {
     TEveTrackList* TrListIn = (TEveTrackList*) fEveTrList->At(i);
diff --git a/fles/mcbm2018/unpacker/CbmMcbm2018UnpackerUtilRich2020.cxx b/fles/mcbm2018/unpacker/CbmMcbm2018UnpackerUtilRich2020.cxx
index bdb1b870628e7754482f7c976e36150092d70162..2819887d431864de8b9f6162c5dd5243d2c6cee8 100644
--- a/fles/mcbm2018/unpacker/CbmMcbm2018UnpackerUtilRich2020.cxx
+++ b/fles/mcbm2018/unpacker/CbmMcbm2018UnpackerUtilRich2020.cxx
@@ -13,13 +13,14 @@ std::string mRichSupport::GetBinaryRepresentation(size_t const size, uint8_t con
   unsigned char* b = (unsigned char*) ptr;
   unsigned char byte;
 
-  char cStr[2];
+  size_t buf_size = 2;
+  char cStr[buf_size];
   cStr[1] = '\0';
 
   for (int i = size - 1; i >= 0; i--) {
     for (int j = 7; j >= 0; j--) {
       byte = (b[i] >> j) & 1;
-      sprintf(cStr, "%u", byte);
+      snprintf(cStr, buf_size - 1, "%u", byte);
       outString.append(cStr);
     }
   }
@@ -37,12 +38,13 @@ std::string mRichSupport::GetHexRepresentation(size_t const size, uint8_t const*
   unsigned char* b = (unsigned char*) ptr;
   unsigned char byte;
 
-  char cStr[3];
+  size_t buf_size = 3;
+  char cStr[buf_size];
   cStr[2] = '\0';
 
   for (int i = size - 1; i >= 0; i--) {
     byte = b[i] & 0xff;
-    sprintf(cStr, "%02x", byte);
+    snprintf(cStr, buf_size - 1, "%02x", byte);
     outString.append(cStr);
   }
 
@@ -60,10 +62,11 @@ std::string mRichSupport::GetWordHexRepr(uint8_t const* const ptr)
   byte[2] = b[1] & 0xff;
   byte[3] = b[0] & 0xff;
 
-  char cStr[10];
+  size_t buf_size = 10;
+  char cStr[buf_size];
   cStr[9] = '\0';
 
-  sprintf(cStr, "%02x%02x %02x%02x", byte[0], byte[1], byte[2], byte[3]);
+  snprintf(cStr, buf_size - 1, "%02x%02x %02x%02x", byte[0], byte[1], byte[2], byte[3]);
 
   outString.append(cStr);
 
@@ -81,10 +84,11 @@ std::string mRichSupport::GetWordHexReprInv(uint8_t const* const ptr)
   byte[2] = b[2] & 0xff;
   byte[3] = b[3] & 0xff;
 
-  char cStr[10];
+  size_t buf_size = 10;
+  char cStr[buf_size];
   cStr[9] = '\0';
 
-  sprintf(cStr, "%02x%02x %02x%02x", byte[0], byte[1], byte[2], byte[3]);
+  snprintf(cStr, buf_size - 1, "%02x%02x %02x%02x", byte[0], byte[1], byte[2], byte[3]);
 
   outString.append(cStr);
 
diff --git a/reco/detectors/trd/pid/CbmTrdElectronsTrainAnn.cxx b/reco/detectors/trd/pid/CbmTrdElectronsTrainAnn.cxx
index 4fc9409edb93eb1d8b0645959a580764d83eaaca..43ac3feea547a8817d0122986a968d84333acdbe 100644
--- a/reco/detectors/trd/pid/CbmTrdElectronsTrainAnn.cxx
+++ b/reco/detectors/trd/pid/CbmTrdElectronsTrainAnn.cxx
@@ -672,10 +672,11 @@ TTree* CbmTrdElectronsTrainAnn::CreateTree()
   fAnnInput.clear();
   fAnnInput.resize(fNofTrdLayers);
   TTree* simu = new TTree("MonteCarlo", "MontecarloData");
-  char txt1[100], txt2[100];
+  size_t buf_size = 100;
+  char txt1[buf_size], txt2[buf_size];
   for (Int_t i = 0; i < fNofTrdLayers; i++) {
-    sprintf(txt1, "x%d", i);
-    sprintf(txt2, "x%d/F", i);
+    snprintf(txt1, buf_size - 1, "x%d", i);
+    snprintf(txt2, buf_size - 1, "x%d/F", i);
     simu->Branch(txt1, &fAnnInput[i], txt2);
   }
   simu->Branch("xOut", &fXOut, "xOut/F");
@@ -686,14 +687,15 @@ TTree* CbmTrdElectronsTrainAnn::CreateTree()
 string CbmTrdElectronsTrainAnn::CreateAnnString()
 {
   string st = "";
-  char txt[50];
+  size_t buf_size = 50;
+  char txt[buf_size];
   for (Int_t i = 0; i < fNofTrdLayers - 1; i++) {
-    sprintf(txt, "x%d", i);
+    snprintf(txt, buf_size - 1, "x%d", i);
     st = st + txt + ",";
   }
-  sprintf(txt, "x%d", fNofTrdLayers - 1);
+  snprintf(txt, buf_size - 1, "x%d", fNofTrdLayers - 1);
   st = st + txt + "";
-  sprintf(txt, "%d", 2 * fNofTrdLayers);
+  snprintf(txt, buf_size - 1, "%d", 2 * fNofTrdLayers);
   st = st + ":" + txt + ":xOut";
   return st;
 }
@@ -709,9 +711,10 @@ TMVA::Factory* CbmTrdElectronsTrainAnn::CreateFactory(TTree*)
   TCut elCut = "xOut>0";
   //TMVA_API
   //factory->SetInputTrees(simu, elCut, piCut);
-  char txt1[100];
+  size_t buf_size = 100;
+  char txt1[buf_size];
   for (Int_t i = 0; i < fNofTrdLayers; i++) {
-    sprintf(txt1, "x%d", i);
+    snprintf(txt1, buf_size - 1, "x%d", i);
     ////TMVA_API
     //factory->AddVariable(txt1, 'F');
   }
@@ -728,9 +731,10 @@ TMVA::Reader* CbmTrdElectronsTrainAnn::CreateTmvaReader()
 
   TMVA::Reader* reader = new TMVA::Reader();
 
-  char txt1[100];
+  size_t buf_size = 100;
+  char txt1[buf_size];
   for (Int_t i = 0; i < fNofTrdLayers; i++) {
-    sprintf(txt1, "x%d", i);
+    snprintf(txt1, buf_size - 1, "x%d", i);
     reader->AddVariable(txt1, &fAnnInput[i]);
   }
   return reader;
diff --git a/reco/tracking/lx/CalcStats/CalcStats.cxx b/reco/tracking/lx/CalcStats/CalcStats.cxx
index 1caa07f8f971ea026c7718cc42716d5534741ca2..dedce8a766ea1390f1d7696d1553faa6ffc7584d 100644
--- a/reco/tracking/lx/CalcStats/CalcStats.cxx
+++ b/reco/tracking/lx/CalcStats/CalcStats.cxx
@@ -42,21 +42,22 @@ InitStatus LxCalcStats::Init()
 
   if (0 == fMCTracks || (0 == fMuchPoints && 0 == fTrdPoints)) LOG(fatal) << "No MC tracks or points";
 
-  char buf[128];
+  size_t buf_size = 128;
+  char buf[buf_size];
 
   for (int i = 0; i < 4; ++i) {
     for (int j = 0; j < 3; ++j) {
-      sprintf(buf, "noise_e_x_%d_%d", i, j);
+      snprintf(buf, buf_size - 1, "noise_e_x_%d_%d", i, j);
       xHistos[i][j] = new TH1F(buf, buf, 240, -30., 30.);
-      sprintf(buf, "noise_e_y_%d_%d", i, j);
+      snprintf(buf, buf_size - 1, "noise_e_y_%d_%d", i, j);
       yHistos[i][j] = new TH1F(buf, buf, 240, -30., 30.);
     }
   }
 
   for (int i = 1; i < 4; ++i) {
-    sprintf(buf, "trdDeltaThetaX_%d", i);
+    snprintf(buf, buf_size - 1, "trdDeltaThetaX_%d", i);
     trdDeltaThetaXHistos[i - 1] = new TH1F(buf, buf, 100, -1.0, 1.0);
-    sprintf(buf, "trdDeltaThetaY_%d", i);
+    snprintf(buf, buf_size - 1, "trdDeltaThetaY_%d", i);
     trdDeltaThetaYHistos[i - 1] = new TH1F(buf, buf, 100, -1.0, 1.0);
   }
 
@@ -171,8 +172,9 @@ void LxCalcStats::Exec(Option_t* /*opt*/)
 static void SaveHisto(TH1F* h)
 {
   TFile* curFile = TFile::CurrentFile();
-  char name[128];
-  sprintf(name, "%s.root", h->GetName());
+  size_t buf_size = 128;
+  char name[buf_size];
+  snprintf(name, buf_size - 1, "%s.root", h->GetName());
   TFile fh(name, "RECREATE");
   h->Write();
   fh.Close();
diff --git a/reco/tracking/lx/GenNoiseElectrons/GenNoiseElectrons.cxx b/reco/tracking/lx/GenNoiseElectrons/GenNoiseElectrons.cxx
index b03e33175293017774f49e6b9034b33f798655e9..ac1527782f665fb16ea4075bf4065bec54538c8b 100644
--- a/reco/tracking/lx/GenNoiseElectrons/GenNoiseElectrons.cxx
+++ b/reco/tracking/lx/GenNoiseElectrons/GenNoiseElectrons.cxx
@@ -45,8 +45,9 @@ static Double_t y_rmss[4][3];
 static Double_t GetRMS(const char* name)
 {
   Double_t result = -1.;
-  char fileName[128];
-  sprintf(fileName, "%s.root", name);
+  size_t buf_size = 128;
+  char fileName[buf_size];
+  snprintf(fileName, buf_size - 1, "%s.root", name);
   TFile* curFile = TFile::CurrentFile();
 
   /// Save old global file and folder pointer to avoid messing with FairRoot
@@ -83,23 +84,24 @@ InitStatus LxGenNoiseElectrons::Init()
 
   if (0 == fMCTracks || 0 == fMuchPoints || 0 == fTrdPoints) LOG(fatal) << "No MC tracks or points";
 
-  char name[128];
+  size_t buf_size = 128;
+  char name[buf_size];
 
   for (int i = 0; i < 4; ++i) {
     for (int j = 0; j < 3; ++j) {
-      sprintf(name, "noise_e_x_%d_%d", i, j);
+      snprintf(name, buf_size - 1, "noise_e_x_%d_%d", i, j);
       x_rmss[i][j] = GetRMS(name);
 
       if (x_rmss[i][j] < 0) {
-        sprintf(name, "Couldn't read noise_e_x_%d_%d", i, j);
+        snprintf(name, buf_size - 1, "Couldn't read noise_e_x_%d_%d", i, j);
         LOG(fatal) << name;
       }
 
-      sprintf(name, "noise_e_y_%d_%d", i, j);
+      snprintf(name, buf_size - 1, "noise_e_y_%d_%d", i, j);
       y_rmss[i][j] = GetRMS(name);
 
       if (y_rmss[i][j] < 0) {
-        sprintf(name, "Couldn't read noise_e_y_%d_%d", i, j);
+        snprintf(name, buf_size - 1, "Couldn't read noise_e_y_%d_%d", i, j);
         LOG(fatal) << name;
       }
     }
diff --git a/reco/tracking/lx/TBBinned/LxTBTask.cxx b/reco/tracking/lx/TBBinned/LxTBTask.cxx
index 4628b0e9091a6b5403fdad3034d018517ae1d817..03aced559ed9d4cd40998026b4ee724dc117bf7e 100644
--- a/reco/tracking/lx/TBBinned/LxTBTask.cxx
+++ b/reco/tracking/lx/TBBinned/LxTBTask.cxx
@@ -1360,12 +1360,13 @@ static void PrintTrigger(list<pair<timetype, timetype>>& signalRecoTimes, list<t
   cout << "Triggered signals(" << name << "): " << eff << "% [ " << nofRecoSignals << " / " << signalMCTimes.size()
        << " ]" << endl;
 
-  char buf[256];
-  sprintf(buf, "triggerings_%s.txt", name);
+  size_t buf_size = 256;
+  char buf[buf_size];
+  snprintf(buf, buf_size - 1, "triggerings_%s.txt", name);
   ofstream triggeringsFile(buf, ios_base::out | ios_base::trunc);
   triggeringsFile << signalRecoTimes.size();
 
-  sprintf(buf, "signal_triggerings_%s.txt", name);
+  snprintf(buf, buf_size - 1, "signal_triggerings_%s.txt", name);
   ofstream signalTriggeringsFile(buf, ios_base::out | ios_base::trunc);
   signalTriggeringsFile << nofRecoSignals;
 
diff --git a/reco/tracking/lx/TBBinned/LxTBTrdTask.cxx b/reco/tracking/lx/TBBinned/LxTBTrdTask.cxx
index 1a13d1c0c6149d70635f7e804386d2a6aa8f7ef5..65aa87d93ade6df92b8e0baa91d90acb378ecdd2 100644
--- a/reco/tracking/lx/TBBinned/LxTBTrdTask.cxx
+++ b/reco/tracking/lx/TBBinned/LxTBTrdTask.cxx
@@ -140,8 +140,9 @@ void LxTBTrdFinder::HandleGeometry()
 
 static bool GetHistoRMS(const char* name, Double_t& retVal)
 {
-  char fileName[64];
-  sprintf(fileName, "%s.root", name);
+  size_t buf_size = 64;
+  char fileName[buf_size];
+  snprintf(fileName, buf_size - 1, "%s.root", name);
   bool result    = false;
   TFile* curFile = TFile::CurrentFile();
 
@@ -187,14 +188,15 @@ InitStatus LxTBTrdFinder::Init()
   }
 
   for (int i = 1; i < 4; ++i) {
-    char name[64];
-    sprintf(name, "trdDeltaThetaX_%d", i);
+    size_t buf_size = 64;
+    char name[buf_size];
+    snprintf(name, buf_size - 1, "trdDeltaThetaX_%d", i);
     Double_t deltaThetaX = 0;
 
     if (!GetHistoRMS(name, deltaThetaX)) return kFATAL;
 
     fFinder->stations[i].deltaThetaX = deltaThetaX;
-    sprintf(name, "trdDeltaThetaY_%d", i);
+    snprintf(name, buf_size - 1, "trdDeltaThetaY_%d", i);
     Double_t deltaThetaY = 0;
 
     if (!GetHistoRMS(name, deltaThetaY)) return kFATAL;
diff --git a/sim/detectors/much/CbmGeoMuch.cxx b/sim/detectors/much/CbmGeoMuch.cxx
index fa6f4b71296c690699fa7274249db548b7e6bcbb..9a47d287fe263c3fb7eebf449e7c8b2291b9f7c6 100644
--- a/sim/detectors/much/CbmGeoMuch.cxx
+++ b/sim/detectors/much/CbmGeoMuch.cxx
@@ -35,7 +35,7 @@ const char* CbmGeoMuch::getModuleName(Int_t m)
   //   if ( m < 9 ) sprintf(modName,"muchstation0%i",m+1);
   //   else  sprintf(modName,"muchstation%i",m+1);
 
-  sprintf(eleName, "much%i", m + 1);
+  snprintf(eleName, 19, "much%i", m + 1);
   //  cout << "DEBUG: modName(" << m << ")="<< modName << endl;
   //  CbmGeoMuchPar* fGeoPar = (CbmGeoMuchPar*) db->getContainer("CbmGeoMuchPar");
 
@@ -45,7 +45,7 @@ const char* CbmGeoMuch::getModuleName(Int_t m)
 const char* CbmGeoMuch::getEleName(Int_t m)
 {
   // Returns the element name of sts number m
-  sprintf(eleName, "much%i", m + 1);
+  snprintf(eleName, 19, "much%i", m + 1);
   return eleName;
 }
 
diff --git a/sim/detectors/sts/qa/CbmStsDigitizeQaReport.cxx b/sim/detectors/sts/qa/CbmStsDigitizeQaReport.cxx
index 6c75296a11388673746b18fec60df897f8b1824a..91eb3dfdf5ad4d02df8826a7d36069c630a076a6 100644
--- a/sim/detectors/sts/qa/CbmStsDigitizeQaReport.cxx
+++ b/sim/detectors/sts/qa/CbmStsDigitizeQaReport.cxx
@@ -54,10 +54,11 @@ void CbmStsDigitizeQaReport::Create()
   Double_t timeResolution = fAsicPar->GetTimeResol();
   Double_t deadTime       = fAsicPar->GetDeadTime();
   Double_t noise          = fAsicPar->GetNoise();
-  char eLossModelChar[15];
-  if (eLossModel == CbmStsELoss::kIdeal) sprintf(eLossModelChar, "ideal");
-  if (eLossModel == CbmStsELoss::kUniform) sprintf(eLossModelChar, "uniform");
-  if (eLossModel == CbmStsELoss::kUrban) sprintf(eLossModelChar, "non-uniform");
+  size_t buf_size         = 15;
+  char eLossModelChar[buf_size];
+  if (eLossModel == CbmStsELoss::kIdeal) snprintf(eLossModelChar, buf_size - 1, "ideal");
+  if (eLossModel == CbmStsELoss::kUniform) snprintf(eLossModelChar, buf_size - 1, "uniform");
+  if (eLossModel == CbmStsELoss::kUrban) snprintf(eLossModelChar, buf_size - 1, "non-uniform");
   Out().precision(1);
   Out() << R()->DocumentBegin();
   Out() << R()->Title(0, GetTitle());
diff --git a/sim/detectors/trd/qa/CbmTrdHitRateFastQa.cxx b/sim/detectors/trd/qa/CbmTrdHitRateFastQa.cxx
index 8e8022bac225f19931eabfc669499a497cdd1cec..05f9a807eb81ebc4463cf438d0bb0a6cafdb2d42 100644
--- a/sim/detectors/trd/qa/CbmTrdHitRateFastQa.cxx
+++ b/sim/detectors/trd/qa/CbmTrdHitRateFastQa.cxx
@@ -272,13 +272,14 @@ void CbmTrdHitRateFastQa::Exec(Option_t*)
   gFile      = oldFile;
   gDirectory = oldDir;
 
-  Char_t name[50];
-  Char_t title[50];
+  size_t buf_size = 50;
+  Char_t name[buf_size];
+  Char_t title[buf_size];
 
 
-  sprintf(name, "HA_S%d_L%d", fStation, fLayer);
+  snprintf(name, buf_size - 1, "HA_S%d_L%d", fStation, fLayer);
   //  sprintf(title,"DataAsic_Station %d, Layer %d",fStation,fLayer);
-  sprintf(title, "Data_per_Asic");
+  snprintf(title, buf_size - 1, "Data_per_Asic");
   //  TH1F* h1HitAsic = new TH1F(name,title,50*fBitPerHit,1,10*fBitPerHit);
   //  TH1F* h1HitAsic = new TH1F(name,title,1000,1,2000);  // Mbit
 
@@ -302,9 +303,9 @@ void CbmTrdHitRateFastQa::Exec(Option_t*)
   h1HitAsic->SetYTitle("count");
   //  h1HitAsic->GetYaxis()->SetRangeUser(0,20);
 
-  sprintf(name, "HM_S%d_L%d", fStation, fLayer);
-  //  sprintf(title,"DataModule_Station %d, Layer %d",fStation,fLayer);
-  sprintf(title, "Data_per_Module");
+  snprintf(name, buf_size - 1, "HM_S%d_L%d", fStation, fLayer);
+  //  sprintf(title, buf_size-1, "DataModule_Station %d, Layer %d",fStation,fLayer);
+  snprintf(title, buf_size - 1, "Data_per_Module");
   //  h1DataModule = new TH1F(name,title,50*fBitPerHit,10,100*10*fBitPerHit);
   //  h1DataModule = new TH1F(name,title,1000,10,100*2000);
 
@@ -328,9 +329,9 @@ void CbmTrdHitRateFastQa::Exec(Option_t*)
   h1DataModule->SetYTitle("count");
   //  h1DataModule->GetYaxis()->SetRangeUser(0,20);
 
-  sprintf(name, "HO_S%d_L%d", fStation, fLayer);
+  snprintf(name, buf_size - 1, "HO_S%d_L%d", fStation, fLayer);
   //  sprintf(title,"OptLinksModule_Station %d, Layer %d",fStation,fLayer);
-  sprintf(title, "5_Gbps_optical_links_per_Module");
+  snprintf(title, buf_size - 1, "5_Gbps_optical_links_per_Module");
   h1OptLinksModule = new TH1F(name, title, 20, 0.5, 20.5);
   h1OptLinksModule->SetXTitle("optical links");
   h1OptLinksModule->SetYTitle("count");
@@ -770,12 +771,13 @@ void CbmTrdHitRateFastQa::ScanModulePlane(const Int_t moduleAddress, TCanvas*& c
 void CbmTrdHitRateFastQa::HistoInit(TCanvas*& c1, TCanvas*& c2, TCanvas*& c3, TH2F*& Layer, TH1F*& HitPad,
                                     Double_t ZRangeL, Double_t ZRangeU, Double_t mm2bin)
 {
-  Char_t name[50];
-  Char_t title[50];
+  size_t buf_size = 50;
+  Char_t name[buf_size];
+  Char_t title[buf_size];
 
 
-  sprintf(name, "HP_S%d_L%d", fStation, fLayer);
-  sprintf(title, "HitPad_Station %d, Layer %d", fStation, fLayer);
+  snprintf(name, buf_size - 1, "HP_S%d_L%d", fStation, fLayer);
+  snprintf(title, buf_size - 1, "HitPad_Station %d, Layer %d", fStation, fLayer);
 
   // set even bin size on logx scale
   const Int_t cnbins = 200;
@@ -796,8 +798,8 @@ void CbmTrdHitRateFastQa::HistoInit(TCanvas*& c1, TCanvas*& c2, TCanvas*& c3, TH
   HitPad->SetYTitle("count");
   HitPad->GetYaxis()->SetRangeUser(1, 1e04);
 
-  sprintf(name, "c2_S%d_L%d", fStation, fLayer);
-  sprintf(title, "c2 Station %d, Layer %d", fStation, fLayer);
+  snprintf(name, buf_size - 1, "c2_S%d_L%d", fStation, fLayer);
+  snprintf(title, buf_size - 1, "c2 Station %d, Layer %d", fStation, fLayer);
   if (fDraw) {
     c2 = new TCanvas(name, title, 1600, 900);
     c2->Divide(2, 2);  // (3,1);
@@ -826,8 +828,8 @@ void CbmTrdHitRateFastQa::HistoInit(TCanvas*& c1, TCanvas*& c2, TCanvas*& c3, TH
     c2->cd(4)->SetGridy(1);
   }
 
-  sprintf(name, "S%d_L%d", fStation, fLayer);
-  sprintf(title, "Station %d, Layer %d", fStation, fLayer);
+  snprintf(name, buf_size - 1, "S%d_L%d", fStation, fLayer);
+  snprintf(title, buf_size - 1, "Station %d, Layer %d", fStation, fLayer);
   printf("%s\n", title);
 
   Layer =
@@ -849,15 +851,15 @@ void CbmTrdHitRateFastQa::HistoInit(TCanvas*& c1, TCanvas*& c2, TCanvas*& c3, TH
   Layer->GetZaxis()->SetRangeUser(ZRangeL, ZRangeU);
   Layer->Fill(0., 0., 0.);
 
-  sprintf(name, "c1_S%d_L%d", fStation, fLayer);
-  sprintf(title, "c1 Station %d, Layer %d", fStation, fLayer);
+  snprintf(name, buf_size - 1, "c1_S%d_L%d", fStation, fLayer);
+  snprintf(title, buf_size - 1, "c1 Station %d, Layer %d", fStation, fLayer);
   if (fDraw) {
     c1 = new TCanvas(name, title, 1000, 900);
     c1->Divide(1, 1);
     c1->cd(1)->SetLogz(1);
     Layer->DrawCopy("colz");
-    sprintf(name, "c3_S%d_L%d", fStation, fLayer);
-    sprintf(title, "c3 Station %d, Layer %d", fStation, fLayer);
+    snprintf(name, buf_size - 1, "c3_S%d_L%d", fStation, fLayer);
+    snprintf(title, buf_size - 1, "c3 Station %d, Layer %d", fStation, fLayer);
     c3 = new TCanvas(name, title, 1000, 900);
     c3->Divide(1, 1);
     c3->cd(1)->SetLogz(1);
diff --git a/sim/detectors/trd/qa/CbmTrdHitRateQa.cxx b/sim/detectors/trd/qa/CbmTrdHitRateQa.cxx
index 2d030f519e4f2523f156eb29a2580dbd8f830352..888031b22fdb4d64821f82d7900848db7d24c66d 100644
--- a/sim/detectors/trd/qa/CbmTrdHitRateQa.cxx
+++ b/sim/detectors/trd/qa/CbmTrdHitRateQa.cxx
@@ -354,8 +354,9 @@ void CbmTrdHitRateQa::Exec(Option_t*)
   LiSi.push_back(Plane09);
   LiSi.push_back(Plane10);
 
-  Char_t OutFile1[200];
-  Char_t OutFile2[200];
+  size_t buf_size = 200;
+  Char_t OutFile1[buf_size];
+  Char_t OutFile2[buf_size];
 
   TImage* Outimage1 = NULL;
   TImage* Outimage2 = NULL;
@@ -386,8 +387,8 @@ void CbmTrdHitRateQa::Exec(Option_t*)
     h2Topview[1]->Reset();
     h2Topview[2]->Reset();
 
-    sprintf(OutFile1, "pics/HitRateLayerPadView_S%d_L%d.png", fStation, fLayer);
-    sprintf(OutFile2, "pics/HitRateLayerSpectrum_S%d_L%d.png", fStation, fLayer);
+    snprintf(OutFile1, buf_size - 1, "pics/HitRateLayerPadView_S%d_L%d.png", fStation, fLayer);
+    snprintf(OutFile2, buf_size - 1, "pics/HitRateLayerSpectrum_S%d_L%d.png", fStation, fLayer);
 
     HistoInit(c1, c2, h2Layer, h1HitPad, ZRangeL, ZRangeU, mm2bin);
 
@@ -427,13 +428,13 @@ void CbmTrdHitRateQa::Exec(Option_t*)
     }
 
     /*
-	sprintf(OutFile1,"pics/%s_S%d_L%d.eps",trddigiparpath,fStation,fLayer);
+	snprintf(OutFile1,buf_size-1,"pics/%s_S%d_L%d.eps",trddigiparpath,fStation,fLayer);
 	c1->cd(1)->Print(OutFile1);
       */
     delete h2Layer;
 
     /*
-	sprintf(OutFile2,"pics/%s_HitPerPad_S%d_L%d.eps",trddigiparpath,fStation,fLayer);
+	snprintf(OutFile2,buf_size-1,"pics/%s_HitPerPad_S%d_L%d.eps",trddigiparpath,fStation,fLayer);
 	c2->cd(1)->Print(OutFile2);
       */
     delete h1HitPad;
@@ -459,11 +460,12 @@ void CbmTrdHitRateQa::Exec(Option_t*)
 void CbmTrdHitRateQa::HistoInit(TCanvas*& c1, TCanvas*& c2, TH2F*& Layer, TH1F*& HitPad, Double_t ZRangeL,
                                 Double_t ZRangeU, Double_t mm2bin)
 {
-  Char_t name[50];
-  Char_t title[50];
+  size_t buf_size = 50;
+  Char_t name[buf_size];
+  Char_t title[buf_size];
 
-  sprintf(name, "S%d_L%d", fStation, fLayer);
-  sprintf(title, "Station %d, Layer %d", fStation, fLayer);
+  snprintf(name, buf_size - 1, "S%d_L%d", fStation, fLayer);
+  snprintf(title, buf_size - 1, "Station %d, Layer %d", fStation, fLayer);
   printf("%s\n", title);
 
   Layer =
@@ -484,23 +486,23 @@ void CbmTrdHitRateQa::HistoInit(TCanvas*& c1, TCanvas*& c2, TH2F*& Layer, TH1F*&
   Layer->GetZaxis()->SetTitleOffset(-2);
   Layer->GetZaxis()->SetRangeUser(ZRangeL, ZRangeU);
 
-  sprintf(name, "HP_S%d_L%d", fStation, fLayer);
-  sprintf(title, "HitPad_Station %d, Layer %d", fStation, fLayer);
+  snprintf(name, buf_size - 1, "HP_S%d_L%d", fStation, fLayer);
+  snprintf(title, buf_size - 1, "HitPad_Station %d, Layer %d", fStation, fLayer);
   HitPad = new TH1F(name, title, 10000, 1e00, 1e06);
   HitPad->SetXTitle("Hits/Pad [Hz]");
   HitPad->SetYTitle("count");
   HitPad->GetYaxis()->SetRangeUser(1, 1e04);
 
-  sprintf(name, "c1_S%d_L%d", fStation, fLayer);
-  sprintf(title, "c1 Station %d, Layer %d", fStation, fLayer);
+  snprintf(name, buf_size - 1, "c1_S%d_L%d", fStation, fLayer);
+  snprintf(title, buf_size - 1, "c1 Station %d, Layer %d", fStation, fLayer);
   if (fDraw) {
     c1 = new TCanvas(name, title, 1000, 900);
     c1->Divide(1, 1);
     c1->cd(1)->SetLogz(1);
     Layer->Draw();
   }
-  sprintf(name, "c2_S%d_L%d", fStation, fLayer);
-  sprintf(title, "c2 Station %d, Layer %d", fStation, fLayer);
+  snprintf(name, buf_size - 1, "c2_S%d_L%d", fStation, fLayer);
+  snprintf(title, buf_size - 1, "c2 Station %d, Layer %d", fStation, fLayer);
   if (fDraw) {
     c2 = new TCanvas(name, title, 1000, 900 / 2);
     c2->Divide(1, 1);
diff --git a/sim/transport/generators/CbmBeamGenerator.cxx b/sim/transport/generators/CbmBeamGenerator.cxx
index f01f014c2725a5af3f21ebf8b7f6af339a1a4edf..2b018e7dba590f447917b5e90465d09e183fb96b 100644
--- a/sim/transport/generators/CbmBeamGenerator.cxx
+++ b/sim/transport/generators/CbmBeamGenerator.cxx
@@ -52,8 +52,9 @@ CbmBeamGenerator::CbmBeamGenerator(UInt_t beamZ, UInt_t beamA, UInt_t beamQ, Dou
 {
 
   // --- Create the ion species and add it to the particle list
-  char name[20];
-  sprintf(name, "Beam_%d_%d_%d", beamZ, beamA, beamQ);
+  size_t buf_size = 20;
+  char name[buf_size];
+  snprintf(name, buf_size - 1, "Beam_%d_%d_%d", beamZ, beamA, beamQ);
   fIon            = new FairIon(name, beamZ, beamA, beamQ);
   FairRunSim* run = FairRunSim::Instance();
   assert(run);
diff --git a/sim/transport/generators/CbmShieldGenerator.cxx b/sim/transport/generators/CbmShieldGenerator.cxx
index c097abf04d45e4cfca07efbde66e0ce90906fb28..70566b1458adda83f89e72df0969adec323b4d41 100644
--- a/sim/transport/generators/CbmShieldGenerator.cxx
+++ b/sim/transport/generators/CbmShieldGenerator.cxx
@@ -131,8 +131,9 @@ Bool_t CbmShieldGenerator::ReadEvent(FairPrimaryGenerator* primGen)
     // Case ion
     /*                       //SELIM
     if ( iPid == 1000 ) {       
-      char ionName[20];
-      sprintf(ionName, "Ion_%d_%d", iMass, iCharge);
+     size_t buf_size = 20;
+     char ionName[buf_size];
+      snprintf(ionName, buf_size-1, "Ion_%d_%d", iMass, iCharge);
       TParticlePDG* part = fPDG->GetParticle(ionName);
       if ( ! part ) {
 	cout << "-W- CbmShieldGenerator::ReadEvent: Cannot find "
@@ -199,9 +200,10 @@ Int_t CbmShieldGenerator::RegisterIons()
       *fInputFile >> pdgType >> iMass >> iCharge >> px >> py >> pz >> etot;  //SELIM: update of SHIELD file structure
                                                                              //if ( iPid == 1000 ) { // ion
       if (pdgType > 1000000000)                                              //SELIM
-      {                                                                      // ion
-        char buffer[20];
-        sprintf(buffer, "Ion_%d_%d", iMass, iCharge);
+      {
+        size_t buf_size = 20;  // ion
+        char buffer[buf_size];
+        snprintf(buffer, buf_size - 1, "Ion_%d_%d", iMass, iCharge);
         TString ionName(buffer);
         if (fIonMap.find(ionName) == fIonMap.end()) {  // new ion
           FairIon* ion     = new FairIon(ionName, iCharge, iMass, iCharge);
diff --git a/sim/transport/generators/pluto/PDataBase.cxx b/sim/transport/generators/pluto/PDataBase.cxx
index 3586238c751e093582814096cd6e13c09223af45..fc9767359769b93825b9413d6a6e0d1178ab7fdc 100644
--- a/sim/transport/generators/pluto/PDataBase.cxx
+++ b/sim/transport/generators/pluto/PDataBase.cxx
@@ -748,10 +748,11 @@ Bool_t PDataBase ::ListEntries(Int_t key, Int_t option, const char* pattern)
             }
           }
           else {
-            char bla[1000];  //I dont know a better way to get the length
+            size_t buf_size = 1000;
+            char bla[buf_size];  //I dont know a better way to get the length
             // (if somebody has an idea -> help yourself)
-            sprintf(bla, "%f", *result);
-            sz[i][pat] = strlen(bla);
+            int results_length = snprintf(bla, buf_size - 1, "%f", *result);
+            sz[i][pat]         = results_length;
             if (sz[i][pat] > max_sz[pat]) max_sz[pat] = sz[i][pat];
             if (checkline && !invert) valid_key[i]++;
             else if (invert && checkline)
@@ -772,10 +773,11 @@ Bool_t PDataBase ::ListEntries(Int_t key, Int_t option, const char* pattern)
             }
           }
           else {
-            char bla[1000];  //I dont know a better way to get the length
+            size_t buf_size = 1000;
+            char bla[buf_size];  //I dont know a better way to get the length
             // (if somebody has an idea -> help yourself)
-            sprintf(bla, "%i", *result3);
-            sz[i][pat] = strlen(bla);
+            int result_length = snprintf(bla, buf_size - 1, "%i", *result3);
+            sz[i][pat]        = result_length;
             if (sz[i][pat] > max_sz[pat]) max_sz[pat] = sz[i][pat];
             if (checkline && !invert) valid_key[i]++;
             else if (invert && checkline)
diff --git a/sim/transport/generators/pluto/PStdData.cxx b/sim/transport/generators/pluto/PStdData.cxx
index 775f73914a62a40d68f4ea528f1833618b7df148..a712c6e09a7e2fb36b98030dc0742fe6aad7145a 100644
--- a/sim/transport/generators/pluto/PStdData.cxx
+++ b/sim/transport/generators/pluto/PStdData.cxx
@@ -164,8 +164,9 @@ Bool_t PStdData::fillDataBase(void)
     if (!base->SetParamDouble(pkey, "ethreshold", dd)) return kFALSE;
 
     //Adding Fireballs!
-    char* name = new char[100];
-    sprintf(name, "Fireball: %s", PStdData::PName[i]);
+    size_t buf_size = 100;
+    char* name      = new char[buf_size];
+    snprintf(name, buf_size - 1, "Fireball: %s", PStdData::PName[i]);
     if ((pkey = base->AddListEntry("std_set", "snpart", "slink", name)) < 0) return kFALSE;
     ii = new int(i + 500);  //never destructed, but called only once!
     if (!base->SetParamInt(pkey, "pid", ii)) return kFALSE;
diff --git a/sim/transport/steer/CbmGeant4Settings.cxx b/sim/transport/steer/CbmGeant4Settings.cxx
index be9d76c414514d926acf486e0279f0d99c9efeba..09ca02d0d0d6993dec37af46792072cd8bdefb79 100644
--- a/sim/transport/steer/CbmGeant4Settings.cxx
+++ b/sim/transport/steer/CbmGeant4Settings.cxx
@@ -32,8 +32,13 @@ void CbmGeant4Settings::Init(TVirtualMC* vmc)
   }
 
   // --- Random seed and maximum number of steps
-  Text_t buffer[50];
-  sprintf(buffer, "/random/setSeeds %i  %i ", gRandom->GetSeed(), gRandom->GetSeed());
+  size_t buf_size = 100;
+  Text_t buffer[buf_size];
+  int result_length =
+    snprintf(buffer, buf_size - 1, "/random/setSeeds %i  %i ", gRandom->GetSeed(), gRandom->GetSeed());
+  if (!(result_length > 0 && result_length < static_cast<int>(buf_size))) {
+    LOG(fatal) << "Buffer overrun. Random seed for Geant4 would be improper.";
+  }
   vmcg4->ProcessGeantCommand(buffer);
 
   vmcg4->SetMaxNStep(fMaxNumSteps);