pike.git / src / stralloc.c

version» Context lines:

pike.git/src/stralloc.c:20:      #include <errno.h>   #include <float.h>   #include <ctype.h>   #include <math.h>      #ifndef HUGE   #define HUGE HUGE_VAL   #endif /*!HUGE*/    - RCSID("$Id: stralloc.c,v 1.130 2001/08/15 11:52:23 hubbe Exp $"); + RCSID("$Id: stralloc.c,v 1.131 2001/08/29 11:51:59 grubba Exp $");      #if PIKE_RUN_UNLOCKED   /* Make this bigger when we get lightweight threads */   #define BUCKET_LOCKS 2048   static PIKE_MUTEX_T *bucket_locks;      #define BUCKETLOCK(HVAL) \    (bucket_locks + ((hval__ % htable_size) & (BUCKET_LOCKS-1)))      #define LOCK_BUCKET(HVAL) do { \
pike.git/src/stralloc.c:1946:       if (mag > s->s->size_shift) {    string_build_mkspace(s, 1, mag);    s->known_shift = (size_t)mag;    } else if (((size_t)s->s->len) >= ((size_t)s->malloced)) {    string_build_mkspace(s, 1, mag);    s->known_shift = MAXIMUM((size_t)mag, s->known_shift);    }    i = s->s->len++;    low_set_index(s->s,i,ch); +  /* Ensure NUL-termination */ +  s->s->str[s->s->len << s->s->size_shift] = 0;   }         PMOD_EXPORT void string_builder_binary_strcat(struct string_builder *s, char *str, ptrdiff_t len)   {    string_build_mkspace(s,len,0);    switch(s->s->size_shift)    {    case 0: convert_0_to_0(STR0(s->s)+s->s->len,(p_wchar0 *)str,len); break;    case 1: convert_0_to_1(STR1(s->s)+s->s->len,(p_wchar0 *)str,len); break;    case 2: convert_0_to_2(STR2(s->s)+s->s->len,(p_wchar0 *)str,len); break;    default:    fatal("Illegal magnitude!\n");    }    s->s->len+=len; -  +  /* Ensure NUL-termination */ +  s->s->str[s->s->len << s->s->size_shift] = 0;   }         PMOD_EXPORT void string_builder_append(struct string_builder *s,    PCHARP from,    ptrdiff_t len)   {    int shift;    if ((shift = from.shift) > s->s->size_shift) {    if (shift == 1) {    shift = find_magnitude1((p_wchar1 *)from.ptr, len);    } else {    shift = find_magnitude2((p_wchar2 *)from.ptr, len);    }    }    string_build_mkspace(s, len, shift);    generic_memcpy(MKPCHARP_STR_OFF(s->s,s->s->len), from, len);    s->s->len+=len; -  +  /* Ensure NUL-termination */ +  s->s->str[s->s->len << s->s->size_shift] = 0;   }      PMOD_EXPORT void string_builder_fill(struct string_builder *s,    ptrdiff_t howmany,    PCHARP from,    ptrdiff_t len,    ptrdiff_t offset)   {    ptrdiff_t tmp;    int shift;
pike.git/src/stralloc.c:2003:   #endif    if(howmany<=0) return;       if(!s->s->size_shift &&    len == 1 &&    (!from.shift || !min_magnitude(EXTRACT_PCHARP(from))))    {    MEMSET(string_builder_allocate(s,howmany,0),    EXTRACT_PCHARP(from),    howmany); +  /* Ensure NUL-termination */ +  s->s->str[s->s->len << s->s->size_shift] = 0;    return;    }       if ((shift = from.shift) > s->s->size_shift) {    /* Check if we really need the extra magnitude. */    /* FIXME: What about offset? */    if (shift == 1) {    shift = find_magnitude1((p_wchar1 *)from.ptr, len);    } else {    shift = find_magnitude2((p_wchar2 *)from.ptr, len);
pike.git/src/stralloc.c:2045:    {    tmp = MINIMUM(len, howmany);    MEMCPY(s->s->str + (s->s->len << s->s->size_shift),    to.ptr,    tmp << s->s->size_shift);    len+=tmp;    howmany-=tmp;    s->s->len+=tmp;    }    } +  /* Ensure NUL-termination */ +  s->s->str[s->s->len << s->s->size_shift] = 0;   }      PMOD_EXPORT void string_builder_strcat(struct string_builder *s, char *str)   {    string_builder_binary_strcat(s,str,strlen(str));   }      PMOD_EXPORT void string_builder_shared_strcat(struct string_builder *s, struct pike_string *str)   {    string_build_mkspace(s,str->len,str->size_shift);       pike_string_cpy(MKPCHARP_STR_OFF(s->s,s->s->len), str);    s->known_shift=MAXIMUM(s->known_shift,(size_t)str->size_shift);    s->s->len+=str->len; -  +  /* Ensure NUL-termination */ +  s->s->str[s->s->len << s->s->size_shift] = 0;   }         PMOD_EXPORT void reset_string_builder(struct string_builder *s)   {    s->known_shift=0;    s->s->len=0; -  +  /* Ensure NUL-termination */ +  s->s->str[0] = 0;   }      PMOD_EXPORT void free_string_builder(struct string_builder *s)   {    s->s->len = s->malloced;    really_free_pike_string(s->s);   }      PMOD_EXPORT struct pike_string *finish_string_builder(struct string_builder *s)   { -  +  /* Ensure NUL-termination */    low_set_index(s->s,s->s->len,0);    if (s->s->len <= SHORT_STRING_THRESHOLD) {    ptrdiff_t len = s->s->len;    s->s->len = s->malloced;    s->s = realloc_unlinked_string(s->s, len);    }    if(s->known_shift == (size_t)s->s->size_shift)    return low_end_shared_string(s->s);    return end_shared_string(s->s);   }