Sponsored Content
Top Forums Programming how to avoid the segfault from Address 0x1cd00000103 out of bounds Post 302277358 by cdbug on Friday 16th of January 2009 04:38:00 AM
Old 01-16-2009
They are pointers. This is sure. But there is some mistakes in the code I gave before. The assignment should use * before the pointers. I am sorry for carelessness when posted. But when checking with 'while ( *( tr->root->is_done ) )', the same segfault happen. And corresponding pinter address still be 'out of bounds". In my code, such statements exist.

This is a package coded by a previous member. He habits to use such structure for varialbes which control execution. A large package means that it is not easy to change all the strutures of this kind.

What's more, I think this is really a topic worth discusssion.



Quote:
Originally Posted by otheus
"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;
 
This correction is good. I losed stars when posted.

And your loop should be:
Code:
while ( *(  tr->root->is_done ) ) {
... 
}
 
At this situation, segfaults still happen

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!
 

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
tsearch(3C)															       tsearch(3C)

NAME
tsearch(), tfind(), tdelete(), twalk() - manage binary search trees SYNOPSIS
DESCRIPTION
and are routines for manipulating binary search trees. They are generalized from Knuth (6.2.2) Algorithms T and D. All comparisons are done with a user-supplied routine, compar. This routine is called with two arguments, the pointers to the elements being compared. It returns an integer less than, equal to, or greater than 0, according to whether the first argument is to be considered less than, equal to or greater than the second argument. The comparison function need not compare every byte, so arbitrary data may be contained in the ele- ments in addition to the values being compared. is used to build and access the tree. key is a pointer to an entry to be accessed or stored. If there is an entry in the tree equal to the value pointed to by key, a pointer to the previous key associated with this found entry is returned. Otherwise, key is inserted, and a pointer to it returned. Note that since the value returned is a pointer to key and key itself is a pointer, the value returned is a pointer to a pointer. Only pointers are copied, so the calling routine must store the data. rootp points to a variable that points to the root of the tree. A NULL value for the variable pointed to by rootp denotes an empty tree; in this case, the variable is set to point to the entry which will be at the root of the new tree. Like searches for an entry in the tree, returning a pointer to it if found. However, if it is not found, returns a NULL pointer. The arguments for are the same as for deletes a node from a binary search tree. Arguments are the same as for The variable pointed to by rootp is changed if the deleted node was the root of the tree. returns a pointer to the parent of the deleted node, or a NULL pointer if the node is not found. traverses a binary search tree. root is the root of the tree to be traversed. (Any node in a tree may be used as the root for a walk below that node.) action is the name of a routine to be invoked at each node. This routine is, in turn, called with three arguments: o First argument is the address of the node being visited. o Second argument is a value from an enumeration data type (defined in the header file), depending on whether this is the first, second or third time that the node has been visited (during a depth-first, left-to-right traversal of the tree), or whether the node is a leaf. o Third argument is the level of the node in the tree, with the root being level zero. EXAMPLES
The following code reads strings, and stores structures containing a pointer to each string and a count of its length. It then walks the tree, printing out the stored strings and their lengths in alphabetical order. RETURN VALUE
A NULL pointer is returned by if there is not enough space available to create a new node. A NULL pointer is returned by and if rootp is NULL on entry. If the datum is found, both and return a pointer to it. If not, returns NULL, and returns a pointer to the inserted item. WARNINGS
The root argument to is one level of indirection less than the rootp arguments to and Two nomenclatures are used to refer to the order in which tree nodes are visited. uses preorder, postorder and endorder to respectively refer to visiting a node before any of its children, after its left child and before its right and after both its children. The alternate nomenclature uses preorder, inorder, and postorder to refer to the same visits, which could result in some confusion over the meaning of postorder. If the calling function alters the pointer to the root, results are unpredictable. SEE ALSO
bsearch(3C), hsearch(3C), lsearch(3C), thread_safety(5). STANDARDS CONFORMANCE
tsearch(3C)
All times are GMT -4. The time now is 10:55 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy