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

[JDEV] FIX in io.c



	I just stumbled accross a comment in io.c in the lib/common directory..

/* There has got to be a better way to do this! */
old = c->buff;
c->buff = malloc(strlen(c->buff) + strlen(buffer) + 1);
c->buff[0] = '\0';
strcpy(c->buff, old);
free(old);
strcat(c->buff, buffer);

	There is a better way.. ;-P

realloc(c->buff, strlen(c->buff) + strlen(buffer) + 1);
strcat(c->buff, buffer);

	MUCH prettier, isn't it??  ;-P  Under Unix do a man malloc, it explains
realloc fairly well..  realloc does exactly what you where doing, but in a
much less overhead way..

--
Thomas Charron
United Parcel Service
Northeast Region
IE Software Developer
"Moving at the speed of a T3 Trunk Line!"