62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
append_str(struct context *ctx, const char *astr, size_t astr_len)
{
char *nbuf;
if (astr_len == 0)
return true;
if (ctx->buf == NULL) {
if ((ctx->buf = malloc(astr_len + 1)) == NULL)
return false;
memcpy(ctx->buf, astr, astr_len);
ctx->buf_len = astr_len;
return true;
}
if ((nbuf = realloc(ctx->buf, ctx->buf_len + astr_len + 1)) == NULL)
return false;
memcpy(nbuf + ctx->buf_len, astr, astr_len);
ctx->buf = nbuf;
ctx->buf_len += astr_len;
|
<
<
<
<
<
<
<
<
<
<
|
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
append_str(struct context *ctx, const char *astr, size_t astr_len)
{
char *nbuf;
if (astr_len == 0)
return true;
if ((nbuf = realloc(ctx->buf, ctx->buf_len + astr_len + 1)) == NULL)
return false;
memcpy(nbuf + ctx->buf_len, astr, astr_len);
ctx->buf = nbuf;
ctx->buf_len += astr_len;
|
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
|
struct context ctx;
ctx.fmt = fmt;
ctx.fmt_len = strlen(fmt);
memset(ctx.subfmt, 0, MAX_SUBFMT_LEN + 1);
ctx.subfmt_len = 0;
va_copy(ctx.args, args);
ctx.buf = NULL;
ctx.buf_len = 0;
ctx.last = 0;
ctx.state = STATE_STRING;
ctx.len_mod = LENGTH_MODIFIER_NONE;
for (ctx.i = 0; ctx.i < ctx.fmt_len; ctx.i++) {
if (!states[ctx.state](&ctx)) {
if (ctx.buf != NULL)
free(ctx.buf);
return -1;
|
<
>
>
>
|
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
|
struct context ctx;
ctx.fmt = fmt;
ctx.fmt_len = strlen(fmt);
memset(ctx.subfmt, 0, MAX_SUBFMT_LEN + 1);
ctx.subfmt_len = 0;
va_copy(ctx.args, args);
ctx.buf_len = 0;
ctx.last = 0;
ctx.state = STATE_STRING;
ctx.len_mod = LENGTH_MODIFIER_NONE;
if ((ctx.buf = malloc(1)) == NULL)
return -1;
for (ctx.i = 0; ctx.i < ctx.fmt_len; ctx.i++) {
if (!states[ctx.state](&ctx)) {
if (ctx.buf != NULL)
free(ctx.buf);
return -1;
|