Exemplo n.º 1
0
/* Ensure strbuf can handle a string length bytes long (ignoring NULL
 * optional termination). */
void strbuf_resize(strbuf_t *s, int len)
{
    int newsize;

    newsize = calculate_new_size(s, len);

    if (s->debug > 1) {
        fprintf(stderr, "strbuf(%lx) resize: %d => %d\n",
                (long)s, s->size, newsize);
    }

    s->size = newsize;
    s->buf = (char*)realloc(s->buf, s->size);
    if (!s->buf)
        die("Out of memory");
    s->reallocs++;
}
Exemplo n.º 2
0
/* Ensure strbuf can handle a string length bytes long (ignoring NULL
 * optional termination). */
int strbuf_resize(strbuf_t *s, int len)
{
    int newsize;

    newsize = calculate_new_size(s, len);

    if (s->debug > 1) {
        NODE_ERR("strbuf(%lx) resize: %d => %d\n",
                (long)s, s->size, newsize);
    }

    s->buf = (char *)cjson_mem_realloc(s->buf, newsize);
    if (!s->buf){
        NODE_ERR("not enough memory");
        return -1;
    }
	s->size = newsize;
    s->reallocs++;
	return 0;
}