Sometimes it just takes another's unbiased eyes to see a problem in code:
The arrays are set up as: "int gintCasePart[30];" and "gstrCasePart[19,40];"
Here are two code snipets I added to the previously working code (hint: it works on Windows, but not Linux): -
...
-
gintCasePart[0] = 1;
-
gintCasePart[1] = 2;
-
gintCasePart[2] = 3;
-
gintCasePart[3] = 4;
-
gintCasePart[4] = 5;
-
gintCasePart[5] = 6;
-
-
if (gblnAngledFlaps == 1)
-
{
-
gintCasePart[6] = 7;
-
gintCasePart[7] = 8;
-
gintCasePart[8] = 9;
-
if (gblnInsertX == 1)
-
{
-
gintCasePart[9] = 10;
-
}
-
}
-
else
-
{
-
gintCasePart[6] = 9;
-
if (gblnInsertX == 1)
-
{
-
gintCasePart[7] = 10;
-
}
-
}
-
and (and I know some of the below is redundant, but it works on the windows side, just not the Linux side... -
if (gblnAngledFlaps==0)
-
{
-
strcpy(gstrCasePart[6],"Cover");
-
gintCasePart[6]=9;
-
gintPartsCount = 7;
-
if (gblnInsertX==1)
-
{
-
strcpy(gstrCasePart[7],"Insert");
-
gintCasePart[7]=10;
-
gintPartsCount = gintPartsCount + 1;
-
}
-
}
-
else
-
{
-
strcpy(gstrCasePart[6],"Inside, Angled Flaps +X+Y, -X-Y");
-
gintCasePart[6]=7;
-
strcpy(gstrCasePart[7],"Inside, Angled Flaps +X-Y, -X+Y");
-
gintCasePart[6]=8;
-
strcpy(gstrCasePart[8],"Cover");
-
gintCasePart[6]=9;
-
gintPartsCount = 9;
-
if (gblnInsertX==1)
-
{
-
strcpy(gstrCasePart[9],"Insert");
-
gintCasePart[6]=10;
-
gintPartsCount = gintPartsCount + 1;
-
}
-
}
-
I also added a debug print statement to attempt to see what was going on in my arrays: -
void check_array(char * func, char * area)
-
{
-
int x;
-
x = 0;
-
printf("In function: %s, In Area: %s",func,area);
-
-
for (x=0;x<=11;x++)
-
{
-
printf("intCasePart = %d, gstrCasePart = %s",gintCasePart[x],gstrCasePart[x]);
-
}
-
}
-
I appreicate any help you can offer, I've been staring at this for nearly 12 hours, and can find no solutions...I'm sure I've just been looking at it too long, without getting a fresh perspective....
Thanks,
Sitko.
6 1441
After reading through more of the SegFault posts, I see a common theme, check your arrays....I've done that, to head you off at the pass.
If I set the arrays to values Greater than the number of elements I'd ever need, should that cover those situations?
I also initialize both arrays with values, 0 for the intArrray, and either the name of the part "Cover", etc, or "" null for the strArray.
Thanks,
Sitko.
Probably it's your strArray elements that cause the problem:
strcpy(gstrCasePart[6],"Inside, Angled Flaps +X+Y, -X-Y");
How are you initializing gstrCasePart[6] ?
Like, did you allocate memory: -
gstrCasePart[6] = (char*)malloc((strlen(,"Inside, Angled Flaps +X+Y, -X-Y") + 1) * sizeof(char));
-
Probably it's your strArray elements that cause the problem:
How are you initializing gstrCasePart[6] ?
Like, did you allocate memory: -
gstrCasePart[6] = (char*)malloc((strlen(,"Inside, Angled Flaps +X+Y, -X-Y") + 1) * sizeof(char));
-
No, I used -
"char gstrCasePart[19][40] = {{"Outside, Long Sides"},{"Outside, Bottom"}, {"Outside, Short Flaps"},{"Outside, Long Flaps"}, {"Inside, Ends"},
-
{"Inside, Side Flaps"},{"Inside, Angled Flaps +X+Y, -X-Y"},
-
{"Inside, Angled Flaps +X-Y, -X+Y"},{"Cover"},{""} //,{""},{""},{""},{""},{""},{""}
-
};
-
To create it. I set it up as a double dimensioned array, where the second dimension would be the chars. And 40 being plenty to contain the largest string of "Inside, Angled Flaps +X-Y, -X+Y"
Is that not a kosher way of doing it?
Thanks,
Sitko.
All,
I found the problem.
It wasn't anything to do with my arrays, although there was one error in there....see if you can find it, and if not, I'll post it later, think of it as a puzzle.
The problem was that I had commented and uncommented out some error checking printf's lower in the code (not presented), and when I was un-commenting them, I by accident un-commented out a bit of code that shouldn't of been un-commented...so basically, I was attempting to call a function that had its declaration commented out, AND its code commented out. But, not the call to it. This leads me to the question, why would this be grouped as a SegFault error, and not an 'un-declared' function, or some such?
Thanks,
Sitko.
It wasn't anything to do with my arrays, although there was one error in there....see if you can find it, and if not, I'll post it later, think of it as a puzzle.
You didn't allocate memory. What you did was assign the address of a constant string to your array elements. Any attempt to copy to that location will crash the program.
so basically, I was attempting to call a function that had its declaration commented out, AND its code commented out. But, not the call to it. This leads me to the question, why would this be grouped as a SegFault error, and not an 'un-declared' function, or some such?
It should cause a build error.
You didn't allocate memory. What you did was assign the address of a constant string to your array elements. Any attempt to copy to that location will crash the program.
It should cause a build error.
thats what I thought as well. In Windows (vb.net) it caused a Linking error...but in Unix, all I got was the segFault.
Thanks.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Nathaniel Echols |
last post by:
I've written a function in C to perform protein sequence alignment. This
works fine in a standalone C program. I've added the necessary packaging
to use it in Python; it returns three strings and...
|
by: Juho Saarikko |
last post by:
The program attached to this message makes the Python interpreter segfault
randomly. I have tried both Python 2.2 which came with Debian Stable, and
self-compiled Python 2.3.3 (newest I could find...
|
by: devesh.agrawal |
last post by:
Hi , this program does a segfault in g++3.2 onwards , works with
g++2.95 ,
Any ideas are welcome , basically there is this instruction when
compiled with -S option , call *%eax , where the one...
|
by: Parahat Melayev |
last post by:
I am programming simple TCP server.
Some packets causes server to get segmentation fault.
Is it possible to handle segmentation fault and log that packet and
make server to continue running?
If...
|
by: Dieter |
last post by:
Hi.
In the snippet of code below, I'm trying to understand why when the
struct dirent ** namelist
is declared with "file" scope, I don't have a problem freeing the
allocated memory. But...
|
by: Richard Heathfield |
last post by:
I found something interesting on the Web today, purely by chance.
It would be funny if it weren't so sad. Or sad if it weren't so funny. I'm
not sure which.
...
|
by: danielesalatti |
last post by:
Hello!!
I'm studying c++ and I'm trying to get a little piece of code working,
but I'm getting a segfault with strlen here:
void tabhash::set (url *U) {
uint hash = U->hashCode();
char* url =...
|
by: andrey.vul |
last post by:
code:
#include <iostream>
#include <vector>
#include <stdexcept>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
|
by: Prasad |
last post by:
Hi folks,
I am trying to debug the following program. Debugging the core file
revealed segfault at possibleFlows=0 when values of
states=36, labels=40. It works fine for lesser values.
What...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
| | |