Re: General method for dynamically allocating memory for a string



websnarf@xxxxxxxxx wrote:
#include <stdlib.h>
#include <string.h>

char * substralloc (const char * src, size_t pos, size_t len) {
size_t i;
char * substr;
if (NULL == src || len < pos) return NULL; /* Bad parameters */

Whoops! That should just be if (NULL == src) return NULL;

--
Paul Hsieh
http://www.pobox.com/~qed/
http://bstring.sf.net/

.