0

this is one of my strangest errors.

QRegularExpression regexp("  .*");

This works fine, sometimes. But than it crashes with segmentation faul.

0   _int_malloc /usr/lib64/libc.so.6        0x7ffff59f2196  
1   malloc  /usr/lib64/libc.so.6        0x7ffff59f411c  
2   operator new(unsigned long) /usr/lib64/libstdc++.so.6       0x7ffff62ac0cd  
3   QRegularExpression::QRegularExpression(QString const&, QFlags<QRegularExpression::PatternOption>)   /usr/lib64/libQt5Core.so.5      0x7ffff6b45fdd  

The Strange thing ist, if i start the program sometimes its okay! No Error at all. Sometime its crashes after this loc was excecuted excacly 71 times.

I just dont have any clue -.-

EDIT:

char hname[255] ="";
char hname80[255] ="";
char hcas[255] = "";
int i = number;

NAMEdll(i,hname,hname80,hcas);

shortName=hname;
fullName=hname80;
cas=hcas;

// remove unecessary spaces
QRegularExpression regexp("  .*");
cas.remove(regexp);
shortName.remove(regexp);
fullName.remove(regexp)

like suggested i removed code to find the error. Its seems to have something to do with NAMEdll ( which is a fortran function). If i take out this command, its all fine. With it i get this:

0   _int_malloc /usr/lib64/libc.so.6        0x7ffff59f2196  
1   malloc  /usr/lib64/libc.so.6        0x7ffff59f411c  
2   QArrayData::allocate(unsigned long, unsigned long, unsigned long, QFlags<QArrayData::AllocationOption>) /usr/lib64/libQt5Core.so.5      0x7ffff6a7c0f6  
3   QRegularExpressionMatchPrivate::QRegularExpressionMatchPrivate(QRegularExpression const&, QString const&, QRegularExpression::MatchType, QFlags<QRegularExpression::MatchOption>, int)  /usr/lib64/libQt5Core.so.5      0x7ffff6b4617a  
4   QRegularExpression::match(QString const&, int, QRegularExpression::MatchType, QFlags<QRegularExpression::MatchOption>) const    /usr/lib64/libQt5Core.so.5      0x7ffff6b475e4  
5   QRegularExpression::globalMatch(QString const&, int, QRegularExpression::MatchType, QFlags<QRegularExpression::MatchOption>) const  /usr/lib64/libQt5Core.so.5      0x7ffff6b47c77  
6   QString::replace(QRegularExpression const&, QString const&) /usr/lib64/libQt5Core.so.5      0x7ffff6b1c4a9  
7   QString::remove qstring.h   429 0x4852fe    

Just guessing, but is there a chance that inside the fortran code (its not my ) something can cause a malloc call to fail ? And if it is so, can someone explain how ?

EDIT:

Solved: Okay i found it by accident. In a diffrent part of the program i had the following code:

char href[3] ="";
strcpy(href,"DEF");

This is bad, cause strcpy also writes an end character '\0'. So the written chararray has the length of 4.

J.W.
  • 81
  • 10
  • 3
    Sounds like a memory error is happening all the time :) You just get lucky some of the time. Did you run it under Valgrind? – jww Jan 12 '15 at 20:54
  • 5
    The problem lies in the surrounding code, which is causing some kind of undefined behaviour. – molbdnilo Jan 12 '15 at 21:01
  • 1
    Probably you are triggering undefined behavior or indeed some memory error. Did you try testing this in both debug / release mode? – cageman Jan 12 '15 at 21:02
  • 3
    Remove parts of your code until the problem disappears. If it still doesn't give you a clue, then start an empty project and start re-adding previously removed pieces until the problems reappears. If this still won't be helpful, then you will have a minimal example that reproduces the problem, and you can post it here. As it is now it's impossible to guess what's wrong in your code. – BartoszKP Jan 12 '15 at 21:08
  • 1
    I removed some code, and i think i found something, see edit.I also will try to take a closer look with valgrind, its just tons of output – J.W. Jan 12 '15 at 21:39
  • @J.W. `is there a chance that inside the fortran code (its not my ) something can cause a malloc call to fail ?` Why do you use the magic `255` as the array size? Is NamedLL documented as to the maximum length of the strings you should send? – PaulMcKenzie Jan 12 '15 at 22:36
  • @J.W. It really doesn't matter what the other language is -- the function (from what you posted) doesn't have any idea if what you're sending is large enough. The Fortran function will stomp on the memory, no different than a C++ program will, therefore it is quite possible that the Fortran function can cause memory corruption, but only due to you passing bad or insufficiently sized parameters. – PaulMcKenzie Jan 12 '15 at 22:37

0 Answers0