[waffle] [PATCH 04/12] core: add JSON library
Emil Velikov
emil.l.velikov at gmail.com
Sun Apr 24 20:50:14 UTC 2016
On 6 January 2016 at 19:56, Frank Henigman <fjhenigman at google.com> wrote:
> +static void
> +put(struct json *jj, char *s)
> +{
> + if (!jj->buf)
> + return;
> +
> + for (;;) {
> + if (!(*jj->pos = *s++))
> + break;
> + if (++jj->pos == jj->buf + jj->size) {
> + size_t z = jj->size * 2;
> + jj->buf = realloc(jj->buf, z);
> + if (!jj->buf)
As I did not look closely at the patch this piece made me believe it
will corrupt the output. Although it will only leak memory.
Namely: if realloc fails, the old pointer is lost yet the data isn't freed.
> + char *buf = malloc(strlen(s) * 3 + 2);
> + if (!buf)
Nit: Just return NULL and drop the label ? Imho there is no point in
jumping only to free(NULL).
Thanks
Emil
More information about the waffle
mailing list