On 04/05/2007 10:36, Enlightenment CVS wrote: > Enlightenment CVS committal > > Author : englebass > Project : e17 > Module : apps/e > > Dir : e17/apps/e/src/bin > > > Modified Files: > e_int_menus.c > > > Log Message: > - No need to use calloc.
Was curious about your reason(s) for not wanting to use calloc. Sometimes the argument is speed. Just wondering your reasons. The main reason I ask is because without it, a bug appears. The reason a bug seems to appear is that I depend on the allocated block being initialized to zeros. The first use of strNcpy below is copying a string of chars whose src is greater in length than the number of chars being copied. The resultant string does not have a null terminator at the end of the src chars copied. Since the block allocated has garbage in it... there can be N chars before a null terminator is found. This is significant because strNcat looks for that null terminator in its first arg, and begins the append there. The result is we wind up with some unforeseen junk in the string. The above bug can be reproduced easily by simply setting the max length of your clientlist menu captions to something quite small... say 10 characters. And then viewing your clientlist menu. Best case we wind up with no junk. Worst case... E seems to segv. One fix is to return to the use of calloc(). Another would be to write a line or two more and make sure abbv has a null terminator where I expect it to be, before continuing with the strncat()s. Please let me know your thoughts on this... and if I've misdiagnosed the problem. > - Use const char to store pointers to title. > > =================================================================== > RCS file: /cvs/e/e17/apps/e/src/bin/e_int_menus.c,v > retrieving revision 1.208 > retrieving revision 1.209 > diff -u -3 -r1.208 -r1.209 > --- e_int_menus.c 4 Apr 2007 13:25:54 -0000 1.208 > +++ e_int_menus.c 5 Apr 2007 15:36:37 -0000 1.209 > @@ -1254,19 +1254,21 @@ > static const char * > _e_int_menus_clients_title_abbrv(const char *title) > { > - char *abbv, *left, *right; > int max_len; > > max_len = e_config->clientlist_max_caption_len; > if ((max_len != 0) && (strlen(title) > max_len)) > { > - abbv = calloc(E_CLIENTLIST_MAX_CAPTION_LEN+4, sizeof(char)); > + char *abbv; > + const char *left, *right; > + > + abbv = malloc(E_CLIENTLIST_MAX_CAPTION_LEN + 4); > left = title; > - right = title + (strlen(title) - (max_len/2)); > - > - strncpy(abbv, left, max_len/2); > + right = title + (strlen(title) - (max_len / 2)); > + > + strncpy(abbv, left, max_len / 2); > strncat(abbv, "...", 3); > - strncat(abbv, right, max_len/2); > + strncat(abbv, right, max_len / 2); > > return abbv; > } > > > > ------------------------------------------------------------------------- > Take Surveys. Earn Cash. Influence the Future of IT > Join SourceForge.net's Techsay panel and you'll get the chance to share your > opinions on IT & business topics through brief surveys-and earn cash > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > _______________________________________________ > enlightenment-cvs mailing list > enlightenment-cvs@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs > > -- Regards, Ravenlock ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys-and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV _______________________________________________ enlightenment-devel mailing list enlightenment-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/enlightenment-devel