# \*\*Break\*\* segmentation violation

**URL:** <https://root-forum.cern.ch/t/break-segmentation-violation/47857>\
**Category:** Newbie\
**Created:** [November 29, 2021, 8:30am UTC](https://root-forum.cern.ch/t/break-segmentation-violation/47857 "2021-11-29T08:30:25Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![priyankaboora](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/priyankaboora/32/25158_2.png) [@priyankaboora](https://root-forum.cern.ch/u/priyankaboora)\
**Post date:** [November 29, 2021, 8:30am UTC](https://root-forum.cern.ch/t/break-segmentation-violation/47857/1 "2021-11-29T08:30:25Z")

</div>

Hi everyone,  
I stuck while compiling the code it shows an error(attachment) of “Break segmentation violation”.  
Please suggest to me how should I resolve this error?

 ![code error](https://root-forum.cern.ch/uploads/default/original/3X/d/4/d46461caa96b3f11569a056933cd092d9acfccea.png)

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [November 29, 2021, 8:49am UTC](https://root-forum.cern.ch/t/break-segmentation-violation/47857/2 "2021-11-29T08:49:15Z")

</div>

I See the error is in TUnixSystem.cxx. I also see you are trying to compile a quite old version (6.14). Can you tell us on which machine you are trying this installation ?

---

<div class="post-metadata">

**Author:** ![eguiraud](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/eguiraud/32/32217_2.png) [@eguiraud](https://root-forum.cern.ch/u/eguiraud)\
**Post date:** [November 29, 2021, 9:38am UTC](https://root-forum.cern.ch/t/break-segmentation-violation/47857/3 "2021-11-29T09:38:31Z")

</div>

Hi @priyankaboora ,  
does this happen when compiling ROOT or compiling/running your own code based on ROOT?

In case it’s the former, note that you don’t have to compile ROOT from source, there are several ways in which you can install ROOT much more quickly, see [Installing ROOT - ROOT](https://root.cern/install) .

Cheers,  
Enrico

---

<div class="post-metadata">

**Author:** ![priyankaboora](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/priyankaboora/32/25158_2.png) [@priyankaboora](https://root-forum.cern.ch/u/priyankaboora)\
**Post date:** [November 29, 2021, 9:45am UTC](https://root-forum.cern.ch/t/break-segmentation-violation/47857/4 "2021-11-29T09:45:39Z")

</div>

Hi,  
This is happening when I am running my own code based on ROOT. For this what should I do?

---

<div class="post-metadata">

**Author:** ![priyankaboora](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/priyankaboora/32/25158_2.png) [@priyankaboora](https://root-forum.cern.ch/u/priyankaboora)\
**Post date:** [November 29, 2021, 9:47am UTC](https://root-forum.cern.ch/t/break-segmentation-violation/47857/5 "2021-11-29T09:47:14Z")

</div>

Actually, ROOT is installed. I am facing this error when running the code.

---

<div class="post-metadata">

**Author:** ![eguiraud](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/eguiraud/32/32217_2.png) [@eguiraud](https://root-forum.cern.ch/u/eguiraud)\
**Post date:** [November 29, 2021, 9:52am UTC](https://root-forum.cern.ch/t/break-segmentation-violation/47857/6 "2021-11-29T09:52:46Z")

</div>

The most likely explanation is that a bug in your code is causing the crash. In particular there seems to be a bad “branchname” parameter being passed to `TTree::FindBranch`.

Standard C++ debugging techniques apply: you can compile your code with the `-g` compilation flag to get debug symbols, so the stacktrace will tell you exactly at what line in `main` the crash happens. And then you can run your code through a debugger, e.g. `gdb`, to inspect exactly what’s going on.

I also suggest to use the `-Wall -Wextra -Wpedantic` compile options to turn on many useful compiler warnings, that sometimes warn about potential bugs.

Cheers,  
Enrico

---

<div class="post-metadata">

**Author:** ![priyankaboora](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/priyankaboora/32/25158_2.png) [@priyankaboora](https://root-forum.cern.ch/u/priyankaboora)\
**Post date:** [November 29, 2021, 11:29am UTC](https://root-forum.cern.ch/t/break-segmentation-violation/47857/7 "2021-11-29T11:29:58Z")

</div>

But the same code works finely on my laptop but shows this above error in work station.

---

<div class="post-metadata">

**Author:** ![eguiraud](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/eguiraud/32/32217_2.png) [@eguiraud](https://root-forum.cern.ch/u/eguiraud)\
**Post date:** [November 29, 2021, 12:47pm UTC](https://root-forum.cern.ch/t/break-segmentation-violation/47857/8 "2021-11-29T12:47:00Z")

</div>

Some categories of C++ bugs can have that behavior (typically because you are in [undefined behavior](https://en.cppreference.com/w/cpp/language/ub) territory so different compilers (or the same compiler with different flags) might generate code that behaves very differently. This is the case e.g. if you use an object after it has been deleted.

Anyway, the simplest way to know is compiling the code with debug symbols and running gdb on it.

Cheers,  
Enrico

---

<div class="post-metadata">

**Author:** ![aheggest](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/b5e925/32.png) [@aheggest](https://root-forum.cern.ch/u/aheggest)\
**Post date:** [January 25, 2022, 5:13am UTC](https://root-forum.cern.ch/t/break-segmentation-violation/47857/9 "2022-01-25T05:13:23Z")

</div>

Hi everyone, I’m having a similar issue with ` ***Break*** segmentation violation`. I’m trying to compile a relatively simple macro I wrote. I will share my code below. The code works fine for 10k entries, but when I try to increase to 100k entries, I see this segmentation violation. I have tried running with gdb to catch errors and I have shared that output below. It doesn’t seem to be a memory issue because I still have space on this machine, and running the `top` command shows that there is available memory. Does anyone have any ideas for what could be going on? Any suggestions or advice is very appreciated.

Thank you,  
Anna H

```auto
Event 8107 already in event vector 

 ***Break*** segmentation violation

===========================================================
There was a crash.
This is the entire stack trace of all threads:
===========================================================
#0 0x00007f9b8745f60c in waitpid () from /lib64/libc.so.6
#1 0x00007f9b873dcf62 in do_system () from /lib64/libc.so.6
#2 0x00007f9b88570ab3 in TUnixSystem::Exec (shellcmd=<optimized out>, this=0x1b79570) at /scratch/workspace/canvas-products-all/vedge-/SLF7/e20-prof/build/root/v6_22_08d/source/root-6.22.08/core/unix/src/TUnixSystem.cxx:2117
#3 TUnixSystem::StackTrace (this=0x1b79570) at /scratch/workspace/canvas-products-all/vedge-/SLF7/e20-prof/build/root/v6_22_08d/source/root-6.22.08/core/unix/src/TUnixSystem.cxx:2408
#4 0x00007f9b8856db85 in TUnixSystem::DispatchSignals (this=0x1b79570, sig=kSigSegmentationViolation) at /scratch/workspace/canvas-products-all/vedge-/SLF7/e20-prof/build/root/v6_22_08d/source/root-6.22.08/core/unix/src/TUnixSystem.cxx:3646
#5 <signal handler called>
#6 0x00007f9b88b6323b in ?? ()
#7 0x00007ffd496830c0 in ?? ()
#8 0x00007ffd496830b8 in ?? ()
#9 0x00007ffd49683068 in ?? ()
#10 0x00007f9b88b63360 in ?? ()
#11 0x00007ffd496830b8 in ?? ()
#12 0x00000000015e8f3c in ?? ()
#13 0x00007ffd496830d0 in ?? ()
#14 0x00007f9b88b63c9a in ?? ()
#15 0x00007ffd496830c8 in ?? ()
#16 0x00007f9b88b631d4 in ?? ()
#17 0x00007ffd496830b8 in ?? ()
#18 0x00007ffd496830c0 in ?? ()
#19 0x00007ffd496830c8 in ?? ()
#20 0x00000000015e8f3c in ?? ()
#21 0x0000000000000000 in ?? ()
===========================================================

The lines below might hint at the cause of the crash.
You may get help by asking at the ROOT forum https://root.cern.ch/forum
Only if you are really convinced it is a bug in ROOT then please submit a
report at https://root.cern.ch/bugs Please post the ENTIRE stack trace
from above as an attachment in addition to anything else
that might help us fixing this issue.
===========================================================
#6 0x00007f9b88b6323b in ?? ()
#7 0x00007ffd496830c0 in ?? ()
#8 0x00007ffd496830b8 in ?? ()
#9 0x00007ffd49683068 in ?? ()
#10 0x00007f9b88b63360 in ?? ()
#11 0x00007ffd496830b8 in ?? ()
#12 0x00000000015e8f3c in ?? ()
#13 0x00007ffd496830d0 in ?? ()
#14 0x00007f9b88b63c9a in ?? ()
#15 0x00007ffd496830c8 in ?? ()
#16 0x00007f9b88b631d4 in ?? ()
#17 0x00007ffd496830b8 in ?? ()
#18 0x00007ffd496830c0 in ?? ()
#19 0x00007ffd496830c8 in ?? ()
#20 0x00000000015e8f3c in ?? ()
#21 0x0000000000000000 in ?? ()
===========================================================

```

Here is my code:

```auto
#include <iostream>
#include <map>
#include "TFile.h"
#include "TH1D.h"
#include <stdio.h>

#include "string"

using namespace std;

void T1_timing(){

  TFile *f1 = new TFile("path/to/my/file/run7449_decoded_ana_172files.root");
  TTree *daqtr = (TTree*)f1->Get("CRTDataAnalysis/DAQTree");
  // Declaration of leaf types                                                                           
  Int_t event;
  Int_t nChan;
  ULong64_t t0;
  ULong64_t t1;
  Int_t adc;
  Int_t entry;
  Int_t mac5;
  Int_t region;
  Int_t subSys;
  UChar_t gate_type;
  //string *gate_name=0;                                                                        
  ULong64_t trigger_timestamp;
  ULong64_t gate_start_timestamp;
  ULong64_t trigger_gate_diff;
  ULong64_t gate_crt_diff;

  // List of branches                                                                                    
  TBranch *b_event; //!                                                                         
  TBranch *b_nChan; //!                                                                         
  TBranch *b_t0; //!                                                                            
  TBranch *b_t1; //!                                                                            
  TBranch *b_adc; //!                                                                           
  TBranch *b_entry; //!                                                                         
  TBranch *b_mac5; //!                                                                          
  TBranch *b_region; //!                                                                        
  TBranch *b_subSys; //!                                                                        
  TBranch *b_gate_type; //!                                                                     
  //TBranch *b_gate_name; //!                                                                   
  TBranch *b_trigger_timestamp; //!                                                             
  TBranch *b_gate_start_timestamp; //!                                                          
  TBranch *b_trigger_gate_diff; //!                                                             
  TBranch *b_gate_crt_diff; //!    

  //set branch addresses and branch pointers                                                             
  daqtr->SetBranchAddress("event", &event, &b_event);
  daqtr->SetBranchAddress("nChan", &nChan, &b_nChan);
  daqtr->SetBranchAddress("t0", &t0, &b_t0);
  daqtr->SetBranchAddress("t1", &t1, &b_t1);
  daqtr->SetBranchAddress("adc", &adc, &b_adc);
  daqtr->SetBranchAddress("entry", &entry, &b_entry);
  daqtr->SetBranchAddress("mac5", &mac5, &b_mac5);
  daqtr->SetBranchAddress("region", &region, &b_region);
  daqtr->SetBranchAddress("subSys", &subSys, &b_subSys);
  daqtr->SetBranchAddress("gate_type", &gate_type, &b_gate_type);
  //daqtr->SetBranchAddress("gate_name", &gate_name, &b_gate_name);                                      
  daqtr->SetBranchAddress("trigger_timestamp", &trigger_timestamp, &b_trigger_timestamp);
  daqtr->SetBranchAddress("gate_start_timestamp", &gate_start_timestamp, &b_gate_start_timestamp);
  daqtr->SetBranchAddress("trigger_gate_diff", &trigger_gate_diff, &b_trigger_gate_diff);
  daqtr->SetBranchAddress("gate_crt_diff", &gate_crt_diff, &b_gate_crt_diff);

  //histos 

  //initialize variables
  ULong64_t temp_maxT1 = 0;
  ULong64_t temp_minT1 = 100000000;
  //make a vector to store each individual mac5's, so we dont overwrite
  vector<int> mac5_vect;
  // make an array to store each FEBs max T1
  ULong64_t maxT1array [93] = {};
  ULong64_t minT1array [93] = {};
  //make a vector to store event #'s
  vector<int> event_vect;
  //get entries                                                                                  
  Long64_t nentries = (Long64_t)daqtr->GetEntries();
  cout << "Reading from CRT DAQTree with " << nentries << " entries...\n";
  for (Int_t i=0; i<100000; i++){     
    daqtr->GetEntry(i);
    if (adc==0) continue;
    //if(mac5!=61)continue; // try to see what 61's max is 
    //mac5_vect.push_back(mac5);
    //check if new event
    if(count(event_vect.begin(), event_vect.end(), event)){
      cout << "Event " << event << " already in event vector \n"; 
    }
    else{
      cout << "New Event! " << event << "\n";
      }
    event_vect.push_back(event);
    if (std::count(mac5_vect.begin(), mac5_vect.end(), mac5)) {
      //std::cout << "Element found, adding to vector " << mac5<<"\n";                            
    }
    else { //clear vectors if a new mac5                                                         
      //break;
      //std::cout << "New mac5!! " << mac5 <<"\n";                                           
      //start over, reset variables to store max/min
      temp_maxT1 = 0;
      temp_minT1 = 100000000;
    }
    mac5_vect.push_back(mac5);
    Int_t temp_mac = mac5;
    ULong64_t temp_t1 = t1; 
    //cout << "Event:" << event << ", i: " << i << ", mac5: " << mac5 << ", t1: " << t1 << "\n";
    
    if (temp_t1 > temp_maxT1){
      //cout << "Max! temp_t1 " << temp_t1 << " is > temp_maxT1 " << temp_maxT1 << "\n";
      temp_maxT1 = temp_t1;
    }
    if (temp_t1 < temp_minT1){
      //cout << "Min! temp_t1 " << temp_t1 << " is < temp_minT1 " << temp_minT1 << "\n";
      temp_minT1 = temp_t1;
    }
    maxT1array[mac5] = temp_maxT1;
    minT1array[mac5] = temp_minT1;
  }
  //cout << "temp_maxT1: " << temp_maxT1 << "\n";
  //cout << "temp_minT1: " << temp_minT1 << "\n";
  
  for(Int_t i=1; i<93; i++){
    if (maxT1array[i] == 0 ) continue;
    if (minT1array[i] == 100000000) continue;
    cout << "Max T1 for feb " << i << ": " << maxT1array[i] << "\n";
  }

}

```

---

<div class="post-metadata">

**Author:** ![dastudillo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/dastudillo/32/17280_2.png) [@dastudillo](https://root-forum.cern.ch/u/dastudillo)\
**Post date:** [January 25, 2022, 5:47am UTC](https://root-forum.cern.ch/t/break-segmentation-violation/47857/10 "2022-01-25T05:47:36Z")

</div>

Given these:

> [@aheggest](#):
>
> ```auto
> ULong64_t maxT1array [93] = {};
> ULong64_t minT1array [93] = {};
> //...
> maxT1array[mac5] = temp_maxT1;
> minT1array[mac5] = temp_minT1;
> 
> ```

a first check is to make sure that mac5 is indeed _always_ \>=0 and \< 93.

---

<div class="post-metadata">

**Author:** ![aheggest](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/b5e925/32.png) [@aheggest](https://root-forum.cern.ch/u/aheggest)\
**Post date:** [January 25, 2022, 6:03am UTC](https://root-forum.cern.ch/t/break-segmentation-violation/47857/11 "2022-01-25T06:03:46Z")

</div>

Thank you so much for your reply. I checked and the mac5 is indeed always greater than 0 and less than 93. I added cout statements to print if the mac5\<0 or if mac5\>93, and these statements were never printed.

---

<div class="post-metadata">

**Author:** ![dastudillo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/dastudillo/32/17280_2.png) [@dastudillo](https://root-forum.cern.ch/u/dastudillo)\
**Post date:** [January 25, 2022, 6:23am UTC](https://root-forum.cern.ch/t/break-segmentation-violation/47857/12 "2022-01-25T06:23:08Z")

</div>

And mac5=93?

---

<div class="post-metadata">

**Author:** ![aheggest](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/b5e925/32.png) [@aheggest](https://root-forum.cern.ch/u/aheggest)\
**Post date:** [January 25, 2022, 6:26am UTC](https://root-forum.cern.ch/t/break-segmentation-violation/47857/13 "2022-01-25T06:26:32Z")

</div>

yes, I have mac5=93 by reading values from the TTree.

---

<div class="post-metadata">

**Author:** ![aheggest](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/b5e925/32.png) [@aheggest](https://root-forum.cern.ch/u/aheggest)\
**Post date:** [January 25, 2022, 6:31am UTC](https://root-forum.cern.ch/t/break-segmentation-violation/47857/14 "2022-01-25T06:31:46Z")

</div>

I tried commenting out my whole code and uncommenting things line by line to try to find where this Segmentation violation occurs. it seems to shows up after i add this line:

```auto
if (temp_t1 > temp_maxT1){
      //cout << "Max! temp_t1 " << temp_t1 << " is > temp_maxT1 " << temp_maxT1 << "\n";           
      temp_maxT1 = temp_t1;
    }
if (temp_t1 < temp_minT1){
      //cout << "Min! temp_t1 " << temp_t1 << " is < temp_minT1 " << temp_minT1 << "\n";           
      temp_minT1 = temp_t1;

```

and it seems the Seg violation interrupts at entry 39330 out of 100000. However, if i just try to read all 100000 entries, and not do anything with finding the min/max, it will loop through all entries just fine. So I can at least access those entries and they are not empty.

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [January 25, 2022, 9:04am UTC](https://root-forum.cern.ch/t/break-segmentation-violation/47857/15 "2022-01-25T09:04:56Z")

</div>

If you have “`mac5=93`” then you need “`...T1array [94]`” (at least).

---

<div class="post-metadata">

**Author:** ![aheggest](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/b5e925/32.png) [@aheggest](https://root-forum.cern.ch/u/aheggest)\
**Post date:** [January 25, 2022, 4:17pm UTC](https://root-forum.cern.ch/t/break-segmentation-violation/47857/16 "2022-01-25T16:17:50Z")

</div>

This seemed to fix it. Thanks so much!
