In our application code we experienced a crash when transitioning to 10.7.p01, which we have attributed to the following new code in G4UIQt.cc: ``` for (size_t i = 0; i < aString.length() - 1; ++i) { if (aString[i] == '\n') { aStringWithStyle += "<br>"; } else if (aString[i] == ' ') { aStringWithStyle += " "; } else if (aString[i] == '\t') { aStringWithStyle += " "; } else { aStringWithStyle += aString[i]; } } ``` On systems where size_t is unsigned int, and when aString is the empty string, aString.length() is zero and the upper index on the loop becomes +2^32-2. This results in a segmentation fault with i at some large value. To fix this issue, we just add an additional requirement to the for loop condition: ``` for (size_t i = 0; i < aString.length() && i < aString.length() - 1; ++i) { ``` though other fixes are possible. It seems this may be caused by `G4cout << G4endl` lines in our application code.
Some more info, as I figure this out myself. This is not related to `G4cout << G4endl` lines. Why does G4cout receive an empty string? In our application code we set `G4cout.setstate(std::ios_base::failbit)` before a bit of geant4 code that we can't make less verbose with standard methods (G4GDMLParser). This effectively prevents output (until this issue). We then clear this state with `G4cout.clear()`. Since this is clearly caused by some code in our application code, I have downgraded the severity to P3/normal. We can work around it by not playing tricks on G4cout.
Problem already addressed and correction in G4UIQt will be included in a future patch. *** This problem has been marked as a duplicate of problem 2347 ***
> Why does G4cout receive an empty string? In our application code we set `G4cout.setstate(std::ios_base::failbit)` before a bit of geant4 code that we can't make less verbose with standard methods (G4GDMLParser). This effectively prevents output (until this issue). We then clear this state with `G4cout.clear()`. > Since this is clearly caused by some code in our application code, I have downgraded the severity to P3/normal. We can work around it by not playing tricks on G4cout. Ah, yes! Strongly recommend not using this "trick". Nevertheless, we have fixed this "empty string" problem for the next release - see Bug #2347. It involves simply replacing if (!aString) return 0; by if(aString.empty()) return 0; If quietening G4cout is a requirement, please submit by the usual channel - the Technical Forum. We will see if there is a hygienic way of doing it.