Re: appending a clist row



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 you code is executed more
than once.

Right, that's what I was saying. :)


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:

Dynamically allocated memory can never be free()'ed? O.o


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

Well no, what you were saying is basically assuming that the buffers are
not modified by gtk_clist_append().

The original post hinted, that the user wanted modifyable array of
strings, hence is why I suggested to allocate each one, passing, then
deallocating.



--
Sincerely,                  ,"-_                         \|/
-Capt. Taura M.             ,   O=__                    --X--
..__                         ,_JNMNNEO=_                 /|\
OMNOUMmnne.                  {OMMNNNEEEEOO=_
UOOOBIOOOEOMMn.               'LONMMMMNNEEEOOO=.__..,,..
UUOOEUUOOOOOOOObe              '"=OMMMMWNEEEOOOOO,"=OEEEOO=,._
OOUUUIEEIOONNOIUbe.                "7OMMMMNNNNNWWEEEEOOOOOO"   "'.
EEBNNMMMNWNWWEEIMMNe.             __  7EMMMNNNNNWWWEEEEEEEOO.     " .
NNMMMMWWWMMMWEINMMMNn            "=BBEEEEMMMMMMMMNNNWWWEEOOOOO=._     .
                  http://furry.ao.net/~learfox/





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