Re: Pointer corruption errors...
- From: Markus Lausser <sgop users sourceforge net>
- To: gtk-app-devel-list gnome org
- Subject: Re: Pointer corruption errors...
- Date: Thu, 11 Jan 2001 02:58:50 +0100
On Tue, Jan 09, 2001 at 08:13:08PM -0500 Craig Durkin wrote:
First off, thanks for your reply. A lot of the stuff that you noted as errors were things I had put in
there to test if it was some sort of memory issue I was missing. The reason I'm using readdir, instead of
getdents and stat, is because I had this problem in a previous attempt at this function which used getdents
and stat, and I wanted to try a different approach. As it stands now, the function is:
GtkWidget
*recurse_dir2(gchar *path) {
GtkWidget *tree, *root;
DIR *dir;
struct dirent *dirent;
tree = gtk_tree_new();
root = gtk_tree_item_new_with_label(path);
gtk_tree_append(GTK_TREE(tree), root);
if (!(dir = opendir(path)))
return 0;
while ((dirent = readdir(dir)) != NULL)
{
if (dirent->d_type == DT_DIR && *dirent->d_name != '.')
{
return 1;
}
dirent = (struct dirent *)((unsigned int)dirent+dirent->d_reclen
);
}
return tree;
}
The only real change is just the absence of the mallocs, but the pointer corruption still occurs. *root is
0x8089800 after gtk_tree_item_new_with_label(), 0x8089780 after gtk_tree_append(), and 0x805f4e0 after if
(!(dir = opendir(path)))
This is starting to seem erratic enough that I'm beginning to think that it isn't a result of poor coding.
:)
Thanks
Craig
Hm, this codes seems to be ok in general.
Remarks:
1. better return NULL instead of 1.
2. the last line inside the while loop is useless, just delete it.
The only reason for your problem that i could imagine is the variable *path.
Be sure, that it is well allocated when you call this function.
I am not sure if this _could_ be a problem, but better check it.
Markus.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]