Revision: 14343 Author: adrian.chadd Date: Mon Oct 26 21:41:49 2009 Log: Attempt to fix issue #72 - modify the String Dup function(s) to return NULL on an empty string
The 'old' behaviour was to just use strBuf() to get a C string pointer. This meant that it would return a NULL pointer if the String was setup but not initialised to anything (ie, "empty"). This patch implements the same behaviour. http://code.google.com/p/lusca-cache/source/detail?r=14343 Modified: /branches/LUSCA_HEAD/libmem/String.c ======================================= --- /branches/LUSCA_HEAD/libmem/String.c Wed Jul 29 19:59:01 2009 +++ /branches/LUSCA_HEAD/libmem/String.c Mon Oct 26 21:41:49 2009 @@ -130,14 +130,23 @@ } /* - * This routine REQUIRES the string to be something and not NULL + * This routine SHOULD REQUIRE the string to be something and not NULL + * but plenty of code unfortunately doesn't check whether the string + * was empty in the first place. + * + * New code MUST NOT call this on an unset string. + * * This copies -from- offset to the end of the string. */ char * stringDupToCOffset(const String *s, int offset) { char *d; - assert(s->buf); + + /* This is horribly temporary [ahc] */ + if (s->buf == NULL) + return NULL; + assert(offset <= s->len); d = xmalloc(s->len + 1 - offset); memcpy(d, s->buf + offset, s->len - offset); @@ -156,7 +165,11 @@ { char *d; int l = XMIN(len, s->len); - assert(s->buf); + + /* This is horribly temporary [ahc] */ + if (s->buf == NULL) + return NULL; + assert(len <= s->len); d = xmalloc(l + 1); memcpy(d, s->buf, l + 1); --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "lusca-commit" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/lusca-commit?hl=en -~----------~----~----~----~------~----~------~--~---
