71fnRVVm
April 3rd, 2008, 10:35 PM
Hi everyone,
What I've found is apparently a bug in the GCC compiler, but here's the story and why I can't fix it:
I'm developing a C++ Program, which right now just reads a file, that is to run on a CentOS5 server, but I'm writing it locally where possible.
Current code:
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
using namespace std;
int main() {
string buffer, temp, to[500], title[500], body[500];
int pos1, pos2, count, rCount;
FILE * inUse;
// Create "locking file"
inUse = fopen("/home/osadmin/data/jabberInUse", "w");
fclose(inUse);
// Read file into buffer
ifstream jabberQueue;
jabberQueue.open("/home/osadmin/data/jabberQueue", ios::in);
if (jabberQueue.is_open()) {
rCount = 0;
while (!jabberQueue.eof()) {
count = 1;
pos2 = 0;
getline(jabberQueue,buffer, '\n');
while (count <= 3) {
pos1 = pos2 + 2;
pos2 = buffer.find("~|",pos1);
temp = buffer.substr(pos1,pos2 - pos1);
if (count == 1) {
to[rCount] = temp;
} else if (count == 2) {
title[rCount] = temp;
} else if (count == 3) {
body[rCount] = temp;
}
count++;
}
}
jabberQueue.close();
}
remove("/home/osadmin/data/jabberInUse");
return 0;
}
The error (originally seen on the server at compiling):
root@host [/home/osadmin/libc/source/jabberQueue]# /usr/local/gcc-4-2/bin/g++4.2 main.cpp -o main
root@host [/home/osadmin/libc/source/jabberQueue]# ./main
terminate called after throwing an instance of 'std::out_of_range'
what(): basic_string::substr
Aborted
On my system, using "gcc (GCC) 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2)" I don't have any errors in compiling or at runtime.
On the server, which was upgraded to "gcc4.2 (GCC) 4.2.0" after finding this problem, it still returns the same error... but this time at runtime, and *not* at compiling.
The hosts have thrown in the towel on this one for support, saying it's now a code problem. But in doing some poking around the internet, it's supposed to be a bug... but 4.2 is causing problems, where 4.1.3 isn't?
Any ideas/help are appreciated.
Thanks
What I've found is apparently a bug in the GCC compiler, but here's the story and why I can't fix it:
I'm developing a C++ Program, which right now just reads a file, that is to run on a CentOS5 server, but I'm writing it locally where possible.
Current code:
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
using namespace std;
int main() {
string buffer, temp, to[500], title[500], body[500];
int pos1, pos2, count, rCount;
FILE * inUse;
// Create "locking file"
inUse = fopen("/home/osadmin/data/jabberInUse", "w");
fclose(inUse);
// Read file into buffer
ifstream jabberQueue;
jabberQueue.open("/home/osadmin/data/jabberQueue", ios::in);
if (jabberQueue.is_open()) {
rCount = 0;
while (!jabberQueue.eof()) {
count = 1;
pos2 = 0;
getline(jabberQueue,buffer, '\n');
while (count <= 3) {
pos1 = pos2 + 2;
pos2 = buffer.find("~|",pos1);
temp = buffer.substr(pos1,pos2 - pos1);
if (count == 1) {
to[rCount] = temp;
} else if (count == 2) {
title[rCount] = temp;
} else if (count == 3) {
body[rCount] = temp;
}
count++;
}
}
jabberQueue.close();
}
remove("/home/osadmin/data/jabberInUse");
return 0;
}
The error (originally seen on the server at compiling):
root@host [/home/osadmin/libc/source/jabberQueue]# /usr/local/gcc-4-2/bin/g++4.2 main.cpp -o main
root@host [/home/osadmin/libc/source/jabberQueue]# ./main
terminate called after throwing an instance of 'std::out_of_range'
what(): basic_string::substr
Aborted
On my system, using "gcc (GCC) 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2)" I don't have any errors in compiling or at runtime.
On the server, which was upgraded to "gcc4.2 (GCC) 4.2.0" after finding this problem, it still returns the same error... but this time at runtime, and *not* at compiling.
The hosts have thrown in the towel on this one for support, saying it's now a code problem. But in doing some poking around the internet, it's supposed to be a bug... but 4.2 is causing problems, where 4.1.3 isn't?
Any ideas/help are appreciated.
Thanks