Re: question ong_list_insert_sorted usage

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Globe Trotter wrote:
Hi,

OK, I know this is not a list for this question, but I have posted on the GTK
list, but that is very low volume, and the answer is killing me. So, I
apologize for this question, but after struggling with this for over a day, I
wanted to ask you for your help regarding usage for g_list_insert_sorted. Can
someone please help. Here are the operative parts of my program:

I have the following struct:

typedef struct _message_info
{
char *from;
char *subject;
char *face;
long *ctime;
} MESSAGE_INFO;

I have the following comparison function:

static gint compare_ctime (gconstpointer a, gconstpointer b)
{
const MESSAGE_INFO *p1=a,*p2=b;

return ((p1->ctime > p2->ctime) ? +1: (p1->ctime == p2->ctime) ? 0 : -1);
}

and the following calling part:

Glist *headers;
.....
   MESSAGE_INFO *m;
   m = g_new(MESSAGE_INFO,1);
   m->from = safe_strdup (from);
   m->subject = safe_strdup (subject);
   m->face = safe_strdup (xface);
   m->ctime = ctime;
   headers = g_list_insert_sorted (headers, m,(GCompareFunc)compare_ctime);
....

I get segmentation fault with this, and was wondering how I could fix it. I
guess my question is how to use g_list_insert_sorted.

I have Googled quite a bit on this, but have not been able to devise the fix.
This is a programming error, I think, based on my inadequate knowledge. Any
help would be very appreciated.
Many thanks and best wishes,
trotter

DISCLAIMER: I don't know what I'm writing about!

"m->ctime = ctime;" looks suspect. I don't see the definition of "ctime" in your code fragment, but it looks like you're assigning a long to a pointer.

Either in MESSAGE_INFO ctime should be declared "long ctime" or the assignment should be m->ctime = & ctime;

Hope this isn't totally off base.

Regards,

John



--
fedora-list mailing list
fedora-list@xxxxxxxxxx
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list
[Index of Archives]     [Older Fedora Users]     [Fedora Announce]     [Fedora Package Announce]     [EPEL Announce]     [Fedora Magazine]     [Fedora News]     [Fedora Summer Coding]     [Fedora Laptop]     [Fedora Cloud]     [Fedora Advisory Board]     [Fedora Education]     [Fedora Security]     [Fedora Scitech]     [Fedora Robotics]     [Fedora Maintainers]     [Fedora Infrastructure]     [Fedora Websites]     [Anaconda Devel]     [Fedora Devel Java]     [Fedora Legacy]     [Fedora Desktop]     [Fedora Fonts]     [ATA RAID]     [Fedora Marketing]     [Fedora Management Tools]     [Fedora Mentors]     [SSH]     [Fedora Package Review]     [Fedora R Devel]     [Fedora PHP Devel]     [Kickstart]     [Fedora Music]     [Fedora Packaging]     [Centos]     [Fedora SELinux]     [Fedora Legal]     [Fedora Kernel]     [Fedora OCaml]     [Coolkey]     [Virtualization Tools]     [ET Management Tools]     [Yum Users]     [Tux]     [Yosemite News]     [Gnome Users]     [KDE Users]     [Fedora Art]     [Fedora Docs]     [Asterisk PBX]     [Fedora Sparc]     [Fedora Universal Network Connector]     [Libvirt Users]     [Fedora ARM]

  Powered by Linux