473,568 Members | 3,014 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Seg fault even though address space is accessible

Hi All,

I got a segmentation fault while accessing a structure element.
I pasted the output from gdb and the backtrace.

However if I am able successfully access the structure using the
address from the gdb output
after it seg faulted. Output from gdb also give below.

Any idea y this is happening?
yes I am trying to access the structure element from where it seg
faulted.

I am surely missing something.
Any help is appreciated!

Thanks,
Ajay.

$$$$$$$$$$$$$ SEG FAULT $$$$$$$$$$$$$$$ $$

Program received signal SIGSEGV, Segmentation fault.
checkBFVectorLi st (BFVecList=0x84 187a0, BFlen=699)
at compute_sticky_ IP_per_ASN.c:77 6
776 vector = vector->nextVector;

$$$$$$$$$$$$$$$ $ BT $$$$$$$$$$$$$$$ $$$$$

(gdb) bt
#0 checkBFVectorLi st (BFVecList=0x84 187a0, BFlen=699)
at compute_sticky_ IP_per_ASN.c:77 6
#1 0x08051bb3 in buildPeerDetail StructFromLine (line=0x8418dd0 "566",
peerStruct=0x80 47124) at compute_sticky_ IP_per_ASN.c:75 2
#2 0x080522c1 in main (argc=11, argv=0x8047348)
at compute_sticky_ IP_per_ASN.c:17 9

$$$$$$$$$$$$$$$ $$$$$ ACCESSING STRUCTURE $$$$$$$$$$$$$$$ $$$$

(gdb) p *(bitfieldItemS truct *) 0x84187a0
$1 = {BFVector = 3309413121, nextVector = 0x84187b0}
(gdb) p ((bitfieldItemS truct *) 0x84187a0)->nextVector
$2 = (struct bitfieldItem *) 0x84187b0
(gdb) p ((struct bitfieldItem *) 0x84187a0)->nextVector
$3 = (struct bitfieldItem *) 0x84187b0
Jul 29 '08 #1
36 1921
On Jul 29, 2:52*pm, Ajay <ajay.todim...@ gmail.comwrote:
Hi All,

I got a segmentation fault while accessing a structure element.
I pasted the output from gdb and the backtrace.

However if I am able successfully access the structure using the
address from the gdb output
after it seg faulted. Output from gdb also give below.

Any idea y this is happening?
yes I am trying to access the structure element from where it seg
faulted.

I am surely missing something.
Any help is appreciated!

Thanks,
Ajay.

$$$$$$$$$$$$$ SEG FAULT $$$$$$$$$$$$$$$ $$

Program received signal SIGSEGV, Segmentation fault.
checkBFVectorLi st (BFVecList=0x84 187a0, BFlen=699)
* * at compute_sticky_ IP_per_ASN.c:77 6
776 * * * * * * * * * * vector = vector->nextVector;

$$$$$$$$$$$$$$$ $ BT $$$$$$$$$$$$$$$ $$$$$

(gdb) bt
#0 *checkBFVectorL ist (BFVecList=0x84 187a0, BFlen=699)
* * at compute_sticky_ IP_per_ASN.c:77 6
#1 *0x08051bb3 in buildPeerDetail StructFromLine (line=0x8418dd0 "566",
* * peerStruct=0x80 47124) at compute_sticky_ IP_per_ASN.c:75 2
#2 *0x080522c1 in main (argc=11, argv=0x8047348)
* * at compute_sticky_ IP_per_ASN.c:17 9

$$$$$$$$$$$$$$$ $$$$$ ACCESSING STRUCTURE $$$$$$$$$$$$$$$ $$$$

(gdb) p *(bitfieldItemS truct *) 0x84187a0
$1 = {BFVector = 3309413121, nextVector = 0x84187b0}
(gdb) p ((bitfieldItemS truct *) 0x84187a0)->nextVector
$2 = (struct bitfieldItem *) 0x84187b0
(gdb) p ((struct bitfieldItem *) 0x84187a0)->nextVector
$3 = (struct bitfieldItem *) 0x84187b0
Maybe an alignment problem.
Did you try the GNU groups?
http://www.nabble.com/Gnu---gdb-f1618.html
news:gnu.gdb.bu g
Jul 29 '08 #2
On Jul 29, 6:01*pm, user923005 <dcor...@connx. comwrote:
On Jul 29, 2:52*pm, Ajay <ajay.todim...@ gmail.comwrote:
Hi All,
I got a segmentation fault while accessing a structure element.
I pasted the output from gdb and the backtrace.
However if I am able successfully access the structure using the
address from the gdb output
after it seg faulted. Output from gdb also give below.
Any idea y this is happening?
yes I am trying to access the structure element from where it seg
faulted.
I am surely missing something.
Any help is appreciated!
Thanks,
Ajay.
$$$$$$$$$$$$$ SEG FAULT $$$$$$$$$$$$$$$ $$
Program received signal SIGSEGV, Segmentation fault.
checkBFVectorLi st (BFVecList=0x84 187a0, BFlen=699)
* * at compute_sticky_ IP_per_ASN.c:77 6
776 * * * * * * * * * * vector = vector->nextVector;
$$$$$$$$$$$$$$$ $ BT $$$$$$$$$$$$$$$ $$$$$
(gdb) bt
#0 *checkBFVectorL ist (BFVecList=0x84 187a0, BFlen=699)
* * at compute_sticky_ IP_per_ASN.c:77 6
#1 *0x08051bb3 in buildPeerDetail StructFromLine (line=0x8418dd0 "566",
* * peerStruct=0x80 47124) at compute_sticky_ IP_per_ASN.c:75 2
#2 *0x080522c1 in main (argc=11, argv=0x8047348)
* * at compute_sticky_ IP_per_ASN.c:17 9
$$$$$$$$$$$$$$$ $$$$$ ACCESSING STRUCTURE $$$$$$$$$$$$$$$ $$$$
(gdb) p *(bitfieldItemS truct *) 0x84187a0
$1 = {BFVector = 3309413121, nextVector = 0x84187b0}
(gdb) p ((bitfieldItemS truct *) 0x84187a0)->nextVector
$2 = (struct bitfieldItem *) 0x84187b0
(gdb) p ((struct bitfieldItem *) 0x84187a0)->nextVector
$3 = (struct bitfieldItem *) 0x84187b0

Maybe an alignment problem.
Did you try the GNU groups?http://www.nabble.com/Gnu---gdb-f1618.html
news:gnu.gdb.bu g
Hmmm! I haven't, Let me try that.
But, how can I find if its an alignment problem?

However, I checked the address space which are function parameters.
And it appears it is aligned. :(

-Ajay.
Jul 29 '08 #3
Ajay <aj***********@ gmail.comwrites :
I got a segmentation fault while accessing a structure element.
I pasted the output from gdb and the backtrace.
The usual advice is to post code. Ideally code you have cut right
down but which still exhibits the problem. Doing this often isolates
the issue anyway, but without code to see it is tough...
However if I am able successfully access the structure using the
address from the gdb output
after it seg faulted. Output from gdb also give below.

Any idea y this is happening?
yes I am trying to access the structure element from where it seg
faulted.

I am surely missing something.
Any help is appreciated!

Thanks,
Ajay.

$$$$$$$$$$$$$ SEG FAULT $$$$$$$$$$$$$$$ $$

Program received signal SIGSEGV, Segmentation fault.
checkBFVectorLi st (BFVecList=0x84 187a0, BFlen=699)
at compute_sticky_ IP_per_ASN.c:77 6
776 vector = vector->nextVector;

$$$$$$$$$$$$$$$ $ BT $$$$$$$$$$$$$$$ $$$$$

(gdb) bt
#0 checkBFVectorLi st (BFVecList=0x84 187a0, BFlen=699)
at compute_sticky_ IP_per_ASN.c:77 6
#1 0x08051bb3 in buildPeerDetail StructFromLine (line=0x8418dd0 "566",
peerStruct=0x80 47124) at compute_sticky_ IP_per_ASN.c:75 2
#2 0x080522c1 in main (argc=11, argv=0x8047348)
at compute_sticky_ IP_per_ASN.c:17 9

$$$$$$$$$$$$$$$ $$$$$ ACCESSING STRUCTURE $$$$$$$$$$$$$$$ $$$$

(gdb) p *(bitfieldItemS truct *) 0x84187a0
$1 = {BFVector = 3309413121, nextVector = 0x84187b0}
(gdb) p ((bitfieldItemS truct *) 0x84187a0)->nextVector
$2 = (struct bitfieldItem *) 0x84187b0
(gdb) p ((struct bitfieldItem *) 0x84187a0)->nextVector
$3 = (struct bitfieldItem *) 0x84187b0
To me, this does not show anything interesting. The fault is with
'vector' not 'BFVecList' which is the only thing that has the value
0x84187a0 (as far as I can see). Did you miss out the 'print vector'
output showing it to be equal to 'BFVecList'? Why not just try to
print vector->nextVector rather than using some mysterious (to me)
address?

--
Ben.
Jul 29 '08 #4
Ajay said:
Hi All,

I got a segmentation fault while accessing a structure element.
I pasted the output from gdb and the backtrace.
There's a guy around here somewhere who can debug your problem (no matter
what it is) using only the debugger. Impressive. But if by some strange
chance he doesn't have time to answer your question, you'll have to rely
on the rest of us, and I'm afraid we tend to need to see the source code.

Without it, the most I can suggest is that you may have violated the bounds
of your array. The fact that gdb lets you look at an address outside the
array doesn't mean anything with regard to your program's correctness.

<snip>

--
Richard Heathfield <http://www.cpax.org.uk >
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Jul 29 '08 #5
Ajay <aj***********@ gmail.comwrote:
I got a segmentation fault while accessing a structure element.
I pasted the output from gdb and the backtrace.
Wich is rather useless without seeing the code. Without it the
gdb output is mostly meaningless.
However if I am able successfully access the structure using the
address from the gdb output
after it seg faulted. Output from gdb also give below.
$$$$$$$$$$$$$ SEG FAULT $$$$$$$$$$$$$$$ $$
Program received signal SIGSEGV, Segmentation fault.
checkBFVectorLi st (BFVecList=0x84 187a0, BFlen=699)
at compute_sticky_ IP_per_ASN.c:77 6
776 vector = vector->nextVector;
What value has 'vector here? Did you check that it's an
address you can legally use as a pointer? Without seeing
your code there's nothing that indicates that 'vector'
has anything to do with the address 0x84187a0.
$$$$$$$$$$$$$$$ $ BT $$$$$$$$$$$$$$$ $$$$$
(gdb) bt
#0 checkBFVectorLi st (BFVecList=0x84 187a0, BFlen=699)
at compute_sticky_ IP_per_ASN.c:77 6
#1 0x08051bb3 in buildPeerDetail StructFromLine (line=0x8418dd0 "566",
peerStruct=0x80 47124) at compute_sticky_ IP_per_ASN.c:75 2
#2 0x080522c1 in main (argc=11, argv=0x8047348)
at compute_sticky_ IP_per_ASN.c:17 9
$$$$$$$$$$$$$$$ $$$$$ ACCESSING STRUCTURE $$$$$$$$$$$$$$$ $$$$
(gdb) p *(bitfieldItemS truct *) 0x84187a0
$1 = {BFVector = 3309413121, nextVector = 0x84187b0}
(gdb) p ((bitfieldItemS truct *) 0x84187a0)->nextVector
$2 = (struct bitfieldItem *) 0x84187b0
(gdb) p ((struct bitfieldItem *) 0x84187a0)->nextVector
I don't understand what you're doing here. Doing

p ((bitfieldItemS truct *) 0x84187a0)->nextVector
p ((struct bitfieldItem *) 0x84187a0)->nextVector

looks suspicious. Note that you use the same address in
both cases, just casting it to a different type - or is
it the same? If yes, why do you think it's relevant to
check the same thing twice?

Regards, Jens
--
\ Jens Thoms Toerring ___ jt@toerring.de
\______________ ____________ http://toerring.de
Jul 29 '08 #6
Hi All,

Thanks for all your replays.

I am posting the code here.
typedef struct bitfieldItem {
uint32_t BFVector;
const struct bitfieldItem *nextVector;
} bitfieldItemStr uct, *bitfieldItemSt ructPtr;

main()
{
***
buildBFVectorLi st(currPeerDeta ilItem->bitfieldStr,
&(currPeerDetai lItem->bitfieldVector ));
checkBFVectorLi st(currPeerDeta ilItem->bitfieldVector ,
currPeerDetailI tem->bitfieldLength );

***

}
int checkBFVectorLi st(bitfieldItem Struct **BFVecList, unsigned int
BFlen)
{
bitfieldItemStr uct *vector = *BFVecList;
float numVectors = ceil((float)BFl en/32.0);
float vector_id = 0;
printf ("Verifying BF vector\n");
printf ("BFlen = %d, numvectors = %f\n", BFlen, numVectors);
printf ("The BF vector is: ");
while (vector != NULL)
{
printf ("%d ", vector->BFVector);
vector = vector->nextVector;
vector_id++;
}
printf ("\nvector_i d = %d\n", vector_id);
assert (vector_id == numVectors);
return 1;
}

int
buildBFVectorLi st(char *BFStr, bitfieldItemStr uct **BFVecList)
{
bitfieldItemStr uct *BFVecHead, *currBFVec, *tmpBFVec;
char * bit;
unsigned int num_bits_pushed = 0;
unsigned int total_num_bits_ pushed = 0;
unsigned int num_vectors = 0;

if (verboseLevel >= 7) printf ("The BF string is %s\n", BFStr);
bit = (char *) strtok(BFStr, ",");
BFVecHead = (bitfieldItemSt ruct *) calloc(1,
sizeof(bitfield ItemStruct *));
BFVecHead->BFVector = 0;
BFVecHead->nextVector = NULL;
currBFVec = BFVecHead;
num_vectors = 1;
printf ("Before %u\n", BFVecHead->BFVector);

while (bit != NULL)
{
if (verboseLevel >= 9) printf ("%d: Current bit is %s\n",
total_num_bits_ pushed+1, bit);
if (num_bits_pushe d >= 32) {
printf ("\nAfter %u\n", currBFVec->BFVector);
if (tmpBFVec = (bitfieldItemSt ruct *) calloc(1,
sizeof(bitfield ItemStruct *)) == NULL) {
printf ("Memory reallocation failed for object of type
'bitfieldItemSt ruct*'.\n");
exit(-1);
}
tmpBFVec->BFVector= 0;
tmpBFVec->nextVector = NULL;
currBFVec->nextVector = tmpBFVec;
currBFVec = tmpBFVec;
num_bits_pushed = 0;
num_vectors++;
printf ("Before %u\n", currBFVec->BFVector);
}

currBFVec->BFVector = currBFVec->BFVector << 1;
printf ("%u", atoi(bit));
currBFVec->BFVector += atoi(bit);
num_bits_pushed ++;
total_num_bits_ pushed++;
bit = (char *) strtok(NULL, ",");
}
printf ("\nAfter %u\n", currBFVec->BFVector);
*BFVecList = BFVecHead;
printf ("The total number of bits in the BFvector is %d and num
vectors is %d.\n", total_num_bits_ pushed, num_vectors);
return 1;
}

On Jul 29, 6:18*pm, Ben Bacarisse <ben.use...@bsb .me.ukwrote:
Ajay <ajay.todim...@ gmail.comwrites :
I got a segmentation fault while accessing a structure element.
I pasted the output from gdb and the backtrace.

The usual advice is to post code. *Ideally code you have cut right
down but which still exhibits the problem. *Doing this often isolates
the issue anyway, but without code to see it is tough...
However if I am able successfully access the structure using the
address from the gdb output
after it seg faulted. Output from gdb also give below.
Any idea y this is happening?
yes I am trying to access the structure element from where it seg
faulted.
I am surely missing something.
Any help is appreciated!
Thanks,
Ajay.
$$$$$$$$$$$$$ SEG FAULT $$$$$$$$$$$$$$$ $$
Program received signal SIGSEGV, Segmentation fault.
checkBFVectorLi st (BFVecList=0x84 187a0, BFlen=699)
* * at compute_sticky_ IP_per_ASN.c:77 6
776 * * * * * * * * * * vector = vector->nextVector;
$$$$$$$$$$$$$$$ $ BT $$$$$$$$$$$$$$$ $$$$$
(gdb) bt
#0 *checkBFVectorL ist (BFVecList=0x84 187a0, BFlen=699)
* * at compute_sticky_ IP_per_ASN.c:77 6
#1 *0x08051bb3 in buildPeerDetail StructFromLine (line=0x8418dd0 "566",
* * peerStruct=0x80 47124) at compute_sticky_ IP_per_ASN.c:75 2
#2 *0x080522c1 in main (argc=11, argv=0x8047348)
* * at compute_sticky_ IP_per_ASN.c:17 9
$$$$$$$$$$$$$$$ $$$$$ ACCESSING STRUCTURE $$$$$$$$$$$$$$$ $$$$
(gdb) p *(bitfieldItemS truct *) 0x84187a0
$1 = {BFVector = 3309413121, nextVector = 0x84187b0}
(gdb) p ((bitfieldItemS truct *) 0x84187a0)->nextVector
$2 = (struct bitfieldItem *) 0x84187b0
(gdb) p ((struct bitfieldItem *) 0x84187a0)->nextVector
$3 = (struct bitfieldItem *) 0x84187b0

To me, this does not show anything interesting. *The fault is with
'vector' not 'BFVecList' which is the only thing that has the value
0x84187a0 (as far as I can see). *Did you miss out the 'print vector'
output showing it to be equal to 'BFVecList'? *Why not just try to
print vector->nextVector rather than using some mysterious (to me)
address?

--
Ben.
Jul 29 '08 #7
Ajay <aj***********@ gmail.comwrites :
I am posting the code here.
Makes all the difference... BTW, top-posting is not in favour in the
group.
typedef struct bitfieldItem {
uint32_t BFVector;
const struct bitfieldItem *nextVector;
} bitfieldItemStr uct, *bitfieldItemSt ructPtr;
<snip>
int
buildBFVectorLi st(char *BFStr, bitfieldItemStr uct **BFVecList)
{
bitfieldItemStr uct *BFVecHead, *currBFVec, *tmpBFVec;
char * bit;
unsigned int num_bits_pushed = 0;
unsigned int total_num_bits_ pushed = 0;
unsigned int num_vectors = 0;

if (verboseLevel >= 7) printf ("The BF string is %s\n", BFStr);
bit = (char *) strtok(BFStr, ",");
BFVecHead = (bitfieldItemSt ruct *) calloc(1,
sizeof(bitfield ItemStruct *));
This is wrong. There is no need for calloc (you set the memory
immediately), the cast is unnecessary, and you don't check the result.
However, the reason things go really wrong is the size is not right.

The comp.lang.c approved method is to write:

BFVecHead = malloc(sizeof *BFVecHead);

This way you can see the size is right (provided the type of the
pointer is correct) and you will get an error message if you have
forgotten to include stdlib.h.
BFVecHead->BFVector = 0;
BFVecHead->nextVector = NULL;
currBFVec = BFVecHead;
num_vectors = 1;
printf ("Before %u\n", BFVecHead->BFVector);

while (bit != NULL)
{
if (verboseLevel >= 9) printf ("%d: Current bit is %s\n",
total_num_bits_ pushed+1, bit);
if (num_bits_pushe d >= 32) {
printf ("\nAfter %u\n", currBFVec->BFVector);
if (tmpBFVec = (bitfieldItemSt ruct *) calloc(1,
sizeof(bitfield ItemStruct *)) == NULL) {
Ditto.
printf ("Memory reallocation failed for object of type
'bitfieldItemSt ruct*'.\n");
exit(-1);
}
tmpBFVec->BFVector= 0;
tmpBFVec->nextVector = NULL;
currBFVec->nextVector = tmpBFVec;
currBFVec = tmpBFVec;
num_bits_pushed = 0;
num_vectors++;
printf ("Before %u\n", currBFVec->BFVector);
}

currBFVec->BFVector = currBFVec->BFVector << 1;
printf ("%u", atoi(bit));
currBFVec->BFVector += atoi(bit);
num_bits_pushed ++;
total_num_bits_ pushed++;
bit = (char *) strtok(NULL, ",");
}
printf ("\nAfter %u\n", currBFVec->BFVector);
*BFVecList = BFVecHead;
printf ("The total number of bits in the BFvector is %d and num
vectors is %d.\n", total_num_bits_ pushed, num_vectors);
return 1;
}
--
Ben.
Jul 29 '08 #8
On Jul 29, 7:25*pm, Ben Bacarisse <ben.use...@bsb .me.ukwrote:
Ajay <ajay.todim...@ gmail.comwrites :
I am posting the code here.

Makes all the difference... *BTW, top-posting is not in favour in the
group.


typedef struct bitfieldItem {
* * uint32_t * *BFVector;
* * const struct bitfieldItem *nextVector;
} bitfieldItemStr uct, *bitfieldItemSt ructPtr;
<snip>
int
buildBFVectorLi st(char *BFStr, bitfieldItemStr uct **BFVecList)
{
* * bitfieldItemStr uct *BFVecHead, *currBFVec, *tmpBFVec;
* * char * bit;
* * unsigned int num_bits_pushed = 0;
* * unsigned int total_num_bits_ pushed = 0;
* * unsigned int num_vectors = 0;
* * if (verboseLevel >= 7) printf ("The BF string is %s\n", BFStr);
* * bit = (char *) strtok(BFStr, ",");
* * BFVecHead = (bitfieldItemSt ruct *) calloc(1,
sizeof(bitfield ItemStruct *));

This is wrong. *There is no need for calloc (you set the memory
immediately), the cast is unnecessary, and you don't check the result.
However, the reason things go really wrong is the size is not right.

The comp.lang.c approved method is to write:

* * BFVecHead = malloc(sizeof *BFVecHead);

This way you can see the size is right (provided the type of the
pointer is correct) and you will get an error message if you have
forgotten to include stdlib.h.
* * BFVecHead->BFVector = 0;
* * BFVecHead->nextVector = NULL;
* * currBFVec = BFVecHead;
* * num_vectors = 1;
* * printf ("Before %u\n", BFVecHead->BFVector);
* * while (bit != NULL)
* * {
* * * * if (verboseLevel >= 9) printf ("%d: Current bit is %s\n",
total_num_bits_ pushed+1, bit);
* * * * if (num_bits_pushe d >= 32) {
* * * * * * printf ("\nAfter %u\n", currBFVec->BFVector);
* * * * * * if (tmpBFVec = (bitfieldItemSt ruct *) calloc(1,
sizeof(bitfield ItemStruct *)) == NULL) {

Ditto.
* * * * * * * * printf ("Memory reallocation failed forobject of type
'bitfieldItemSt ruct*'.\n");
* * * * * * * * exit(-1);
* * * * * * }
* * * * * * tmpBFVec->BFVector= 0;
* * * * * * tmpBFVec->nextVector = NULL;
* * * * * * currBFVec->nextVector = tmpBFVec;
* * * * * * currBFVec = tmpBFVec;
* * * * * * num_bits_pushed = 0;
* * * * * * num_vectors++;
* * * * * * printf ("Before %u\n", currBFVec->BFVector);
* * * * }
* * * * currBFVec->BFVector = currBFVec->BFVector << 1;
* * * * printf ("%u", atoi(bit));
* * * * currBFVec->BFVector += atoi(bit);
* * * * num_bits_pushed ++;
* * * * total_num_bits_ pushed++;
* * * * bit = (char *) strtok(NULL, ",");
* * }
* * printf ("\nAfter %u\n", currBFVec->BFVector);
* * *BFVecList = BFVecHead;
* * printf ("The total number of bits in the BFvector is %d and num
vectors is %d.\n", total_num_bits_ pushed, num_vectors);
* * return 1;
}

--
Ben.
Hi Ben,

Thanks for your replay!
I was using malloc but after the error appeared, I tried using calloc.
I changed back the code to using malloc.
The Seg. fault error still persists.
The new code is posted below:

Thanks,
Ajay.

int
checkBFVectorLi st(bitfieldItem Struct **BFVecList, unsigned int BFlen)
{
bitfieldItemStr uct *vector = *BFVecList;
float numVectors = ceil((float)BFl en/32.0);
float vector_id = 0;
printf ("Verifying BF vector\n");
printf ("BFlen = %d, numvectors = %f\n", BFlen, numVectors);
printf ("The BF vector is: ");
while (vector != NULL)
{
/* if (vector->BFVector != NULL) printf ("%u ", vector-
>BFVector);
else { printf ("Error occured\n"); exit(-1); } */
/* printf ("%d ", vector->BFVector);*/
vector = vector->nextVector;
vector_id++;
}
printf ("\nvector_i d = %d\n", vector_id);
assert (vector_id == numVectors);
return 1;
}

int
buildBFVectorLi st(char *BFStr, bitfieldItemStr uct **BFVecList)
{
bitfieldItemStr uct *BFVecHead, *currBFVec, *tmpBFVec;
char * bit;
unsigned int num_bits_pushed = 0;
unsigned int total_num_bits_ pushed = 0;
unsigned int num_vectors = 0;

if (verboseLevel >= 7) printf ("The BF string is %s\n", BFStr);
bit = (char *) strtok(BFStr, ",");
BFVecHead = malloc(sizeof(* BFVecHead));
if (BFVecHead == NULL) {
perror("Error: Memory could not be allocated:");
exit(-1);
}
BFVecHead->BFVector = 0;
BFVecHead->nextVector = NULL;
currBFVec = BFVecHead;
num_vectors = 1;
printf ("Before %u\n", BFVecHead->BFVector);

while (bit != NULL)
{
if (verboseLevel >= 9) printf ("%d: Current bit is %s\n",
total_num_bits_ pushed+1, bit);
if (num_bits_pushe d >= 32) {
printf ("\nAfter %u\n", currBFVec->BFVector);
tmpBFVec = malloc(sizeof(* tmpBFVec));
if (tmpBFVec == NULL) {
perror("Error: Memory could not be allocated:");
exit(-1);
}
tmpBFVec->BFVector= 0;
tmpBFVec->nextVector = NULL;
currBFVec->nextVector = tmpBFVec;
currBFVec = tmpBFVec;
num_bits_pushed = 0;
num_vectors++;
printf ("Before %u\n", currBFVec->BFVector);
}

currBFVec->BFVector = currBFVec->BFVector << 1;
printf ("%u", atoi(bit));
currBFVec->BFVector += atoi(bit);
num_bits_pushed ++;
total_num_bits_ pushed++;
bit = (char *) strtok(NULL, ",");
}
printf ("\nAfter %u\n", currBFVec->BFVector);
*BFVecList = BFVecHead;
printf ("The total number of bits in the BFvector is %d and num
vectors is %d.\n", total_num_bits_ pushed, num_vectors);
return 1;
}

Jul 30 '08 #9
Ajay <aj***********@ gmail.comwrites :
Thanks for your replay!
I was using malloc but after the error appeared, I tried using calloc.
I changed back the code to using malloc.
The Seg. fault error still persists.
The new code is posted below:
Are you sure you are posting code you have compiled?
int
checkBFVectorLi st(bitfieldItem Struct **BFVecList, unsigned int BFlen)
int
buildBFVectorLi st(char *BFStr, bitfieldItemStr uct **BFVecList)
elsewhere you posted:

| main()
| {
| ***
| buildBFVectorLi st(currPeerDeta ilItem->bitfieldStr,
| &(currPeerDetai lItem->bitfieldVector ));
| checkBFVectorLi st(currPeerDeta ilItem->bitfieldVector ,
| currPeerDetailI tem->bitfieldLength );
|
| ***
|
| }

The types here do not match up -- the compiler should reject it.

--
Ben.
Jul 30 '08 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
6794
by: sivignon | last post by:
Hi, I'm writing a php script which deals with 3 ORACLE databases. This script is launch by a script shell on an linux machine like this : /../php/bin/php ./MySript.php (PHP 4.3.3) My script works fine and do all what I need. But at the end of the execution, I can read "Segmentation Fault". The segmentation fault appear at the end of my...
13
22153
by: N.S. du Toit | last post by:
Just having a bit of trouble programming with C under FreeBSD 5.1 using the gcc compiler. I'm a bit new to C so my apologies if the answer to my question appear obvious :) Basically I've written a function that will check whether a string is an ip address (see the function isIP below). During my attempt at debugging this problem I...
3
11395
by: Zheng Da | last post by:
Program received signal SIGSEGV, Segmentation fault. 0x40093343 in _int_malloc () from /lib/tls/libc.so.6 (gdb) bt #0 0x40093343 in _int_malloc () from /lib/tls/libc.so.6 #1 0x40094c54 in malloc () from /lib/tls/libc.so.6 It's really strange; I just call malloc() like "tmp=malloc(size);" the system gives me Segmentation fault I want to...
20
520
by: ramu | last post by:
Hi, int main(void) { char ch='a'; printf("%s",ch); return 0; } Why does this give segmentation fault?
27
3334
by: Paminu | last post by:
I have a wierd problem. In my main function I print "test" as the first thing. But if I run the call to node_alloc AFTER the printf call I get a segmentation fault and test is not printed! #include <stdlib.h> #include <stdio.h> typedef struct _node_t {
8
1614
by: ChristophK | last post by:
Hallo, this is my first post and I hope I'm doing well, but if not, please let me know. My problem: First all classes and a main-file (I simplified everything to get to the core of the problem): /*---------------- start of code ---------------------------*/
59
2864
by: Christian Christmann | last post by:
Hi, I'm wondering why this program does not crash with a segmentation fault: #include <malloc.h> #include <string.h> #include <stdio.h> int main()
0
1157
by: rmashukov | last post by:
Program terminated with signal 11, Segmentation fault. Environment: FreeBSD 6.2, Python 2.4.4, MySQLdb 1.2.2, SQLObject 0.9.1 I faced with an error in our multithreaded, network oriented application, wich interacts actively with MySQL database. Brief information from core dump is below (more detailed one is in the file attached). Though I...
25
3356
by: jbholman | last post by:
I am pretty new to C and doing my first project in C. I actually read almost the entire FAQ, but can't seem to figure out this problem. I have a structure. I have a list of these structures. Inside each structure, I have two members: a list of strings, and a string. I have made a sample program below that exhibits the error I am...
0
7605
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7917
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8118
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7665
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5501
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5217
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3631
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1207
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
933
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.