how to avoid the segfault from Address 0x1cd00000103 out of bounds


 
Thread Tools Search this Thread
Top Forums Programming how to avoid the segfault from Address 0x1cd00000103 out of bounds
# 1  
Old 01-13-2009
how to avoid the segfault from Address 0x1cd00000103 out of bounds

After allocating memory for some variables, segfault is often to happen, due to the same reason: Address 0x1cd00000103 out of bounds

It is welcome to recommend some treatments. Thanks

e.g.

is_done = 0x1cd00000103 <Address 0x1cd00000103 out of bounds>,
hood = 0x23c00000247,
c = 0x1a900000149 <Address 0x1a900000149 out of bounds>,
site = 0x40a000004fc,
site2 = 0x3ba0000059f,
des = 0x47200000199 <Address 0x47200000199 out of bounds>,
asc = 0x47500000056 <Address 0x47500000056 out of bounds>,
# 2  
Old 01-13-2009
Perhaps you should post your code. If for legal or privacy reasons you cannot, then maybe post code from one such function that has these variables.
# 3  
Old 01-14-2009
Let me show it here:

node->is_done = (int *) malloc(sizeof(int));
node->hood = (double *) malloc(sizeof(double));
node->c = (int *) malloc(sizeof(int));
node->site = (double *) malloc(sizeof(double));
node->site2 = (double *) malloc(sizeof(double));double
node->des = (double *) malloc(sizeof(double));
node->asc = (double *) malloc(sizeof(double));

//null checking

node->is_done = 0;
node->hood = 0;
node->c = 1;
node->site = 0;
node->site2 = 0;
node->des = 0;
node->asc = 0

But, use of these varialbes in code will lead to segfaults, e.g. if(node->is_done) { --- }

check these varialbes, those showing 'address 0x1cd00000103 out of bounds' will finally lead to segments

I should remind that some nodes but not all the nodes in a tree will give segfaults when checking if(node->is_done)

It is said that unsuccessful initialization is the source of 'Address 0x1cd00000103 out of bounds'. Concretely speaking, how to avoid such unsuccessful initialization occur in some nodes?

Can we take some measures?
# 4  
Old 01-14-2009
I think you are confused about what you are trying to do! In the examples above, you are allocating memory one address at a time and storing the pointers in your structure inside "node". So node->hood presumably holds a pointer to 4 (or 8) bytes (the size of "double").

Also, where did you allocate memory for node? Presumably you have:
Code:
node = (struct node_t*)malloc(sizeof(struct node_t));

# 5  
Old 01-14-2009
Right!! these are pointers. What does 'out of bounds' mean? More important, how to avoid it? Clearly null checking can not make effect in this respect.

Program received signal SIGSEGV, Segmentation fault.
520 while( tr->root->is_done) { ----}

(gdb) p tr->root->is_done
$2 = (int *) 0x3f500000539 <Address 0x3f500000539 out of bounds>
(gdb) pt tr->root->is_likelihood_done
type = int *

-----------------------------------------------------------------
struct node_t {

int *is_done;
double *hood;
int *c;
double *site;
double *site2;
double *des;
double *asc;

}

Last edited by cdbug; 01-14-2009 at 09:33 PM..
# 6  
Old 01-14-2009
Can you provide us with a short complete example program which exhibits this behaviour?
And provide details of your compilation environment.
# 7  
Old 01-15-2009
"out of bounds" means "invalid memory address". You avoid it by properly mallocing memory before using it.

I hate to say this, but you seem very confused about pointers. I think you need to read a very concise summary on C pointers.

In the code you provide, you are trying to assign values to the address...
Code:
node->des = 0;

You should instead be doing:
Code:
*(node->des) = 0;

And your loop should be:
Code:
while ( *(  tr->root->is_done ) ) {
... 
}

Also, root itself is a pointer. So you first need to allocate it:
Code:
tr->root = malloc(sizeof(struct node_t));
tr->root->hood = malloc(sizeof(double*));

"tr" is also a pointer, and this needs to be allocated too, but I have no idea what kind of structure it is.


Also, this structure is very unusual. I cannot imagine why you want every element to be a pointer to something!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

-Warray-bounds option to GCC compiler

What exactly is the -Warray-bounds option to the GCC compiler supposed to warn about? the man page states: ~ g++ --version g++ (GCC) 7.3.1 20180130 (Red Hat 7.3.1-2) Copyright (C) 2017 Free Software Foundation, Inc.Thank you. (14 Replies)
Discussion started by: milhan
14 Replies

2. Programming

Segfault When Parsing Delimiters In C

Another project, another bump in the road and another chance to learn. I've been trying to open gzipped files and parse data from them and hit a snag. I have data in gzips with a place followed by an ip or ip range sort of like this: Some place:x.x.x.x-x.x.x.x I was able to modify some code... (6 Replies)
Discussion started by: Azrael
6 Replies

3. Shell Programming and Scripting

Grep for string, but within mentioned bounds

Hi, I've been trying to filter a file which has several repetitions of lines which looks as follows: ('hello My name is jamie blabla xyz>>) Each line has different values in them. I want grep or awk or sed to treat everything within the (' and >>) as one line and then filter for a... (2 Replies)
Discussion started by: jamie_123
2 Replies

4. Programming

segfault in pointer to string program

hello all, my question is not about How code can be rewritten, i just wanna know even though i am not using read only memory of C (i have declared str) why this function gives me segfault :wall:and the other code executes comfortably though both code uses same pointer arithmetic. ... (4 Replies)
Discussion started by: zius_oram
4 Replies

5. Programming

Is Drive Valid Segfault

I have a program that allows users to specify the debug log file location and name. I have tried using the access() and stat() but they both segfault if the drive say (d:\) is invalid. Both seem to be fine if the drive exists. Could someone please point me in the direction to a function that... (1 Reply)
Discussion started by: robfwauk
1 Replies

6. Programming

id3lib SEGFAULT

Hello everyone, I'm writing a program using the id3lib unfortunately I've encountered with memory issue that cause segmentation fault. I tried to rerun and analyze the program with valgrind but it doesn't point me anywhere. I really stuck on this one. Valgrind output: ==14716== Invalid read of... (2 Replies)
Discussion started by: errb
2 Replies

7. Solaris

Working around netscape 4.9 segfault on Solaris 8

We have a Solaris 8 server which users login to via VNC to get a desktop. On that desktop these users use Netscape Communicator 4.9 to access a very important mail account. Unfortunately Netscape has started segfaulting regularly. Does anyone have any ideas how I can try to find out what point... (1 Reply)
Discussion started by: aussieos
1 Replies

8. Programming

array bounds and mem leak tool

Is there any freeware to find out array bounds static and dynamic ways in Solaris 10. (1 Reply)
Discussion started by: satish@123
1 Replies

9. UNIX for Dummies Questions & Answers

[Linux] How Do I Run Until Segfault

Hello, sorry if this has been posted before but i was wondering if there is a way to run a program until a segmentation fault is found. Currently i'm using a simple shell script which runs my program 100 times, sleeps 1 second because srand(time(0)) is dependent on seconds. Is there a possible... (1 Reply)
Discussion started by: aslambilal
1 Replies

10. UNIX for Advanced & Expert Users

crontab: error on previous line; number out of bounds.

Hi, I am trying to set up a cron job for every Friday at 6:00 p.m. and got an error: "/var/tmp/aaaa29638" 1 line, 73 characters 00 18 00 0 5 /app/test/backup.ksh crontab: error on previous line; number out of bounds. Any ideas? Thanks! (1 Reply)
Discussion started by: oradbus
1 Replies
Login or Register to Ask a Question