Pointer corruption errors...
- From: Craig Durkin <durkin+gtkad matter net>
- To: gtk-app-devel-list gnome org
- Subject: Pointer corruption errors...
- Date: Tue, 9 Jan 2001 17:44:49 -0500
Hi there. I'm a gtk newbie, and I can't for the life of me figure out this weird error. I'm writing a
directory recursion function to store all directories in a hierarchy in a tree, but I seem to have some
pointer corruption problems. The function is as follows:
GtkWidget
*recurse_dir2(gchar *opath) {
gchar *path = g_malloc(sizeof(char));
GtkWidget *tree, *root = g_malloc(sizeof(GtkWidget));
DIR *dir = g_malloc(sizeof(DIR));
struct dirent *dirent;
strcpy(path, opath);
if (!(dir = opendir(path)))
return 0;
tree = gtk_tree_new();
root = gtk_tree_item_new_with_label(path);
gtk_tree_append(GTK_TREE(tree), root);
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;
}
As you can see, it's a very simple function, mostly because I didn't even get a chance to finish it before I
noticed this error. While stepping through with gdb, *root points to something like say 0x8088900 after
malloc for *root. After the malloc for *dir, *root then changes to point at say 0x805f4a0, for no reason I
can think of. After the call to open(), it then changes to 0x805f4c0. I feel like I'm missing something
pretty obvious, but I don't know how to debug this any further.
Thanks
Craig
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]