Re: appending a clist row
- From: Clemens Kirchgatterer <clemens root at>
- To: gtk-app-devel-list <gtk-app-devel-list redhat com>
- Subject: Re: appending a clist row
- Date: Sun, 07 Jan 2001 16:03:02 +0100
learfox furry ao net wrote:
/* Allocate a blank array of strings. */
text = (char **)malloc(clist_columns * sizeof(char *));
if(text != NULL)
{
/* Set each pointer to point to an allocated empty string. */
for(i = 0; i < clist_columns; i++)
text[i] = strdup("");
}
just for my curiosity: why do you use strdup() instead of passing the
const char * "" ?
I got the impression that the array and or strings within would be
modified.
hmm, a const char* like "bla" or "" is allocated at compiletime and
overwriteing such a string will easyly result in a segfault or buffer
overrun, cause it holds exact as many bytes as necessery. also you have
to free the string to avoid a memory leak if your code is executed more
than once.
I don't know if they are so just to be on the safe side I made coppies.
gtk will hold its own copies, so the dynamically allocate memory is
wasted and can not be freed at runtime. instead of doing:
text = (char **)malloc(clist_columns * sizeof(char *));
you should do:
char *text[COLUMNS];
for(i = 0; i < COLUMNS; i++) text[i] = "";
gtk_clist_append(GTK_CLIST(list), &text[0]);
i hpe i'm not telling bullshit here!!!! ;-)
warm regards ...
clemens
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]