ObjFW  Check-in [a0ff17e12b]

Overview
Comment:Make sure we always have a return buffer in of_asprintf.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: a0ff17e12bc72967758fc99eab0146a55716b985ffc0c7026b915832423e51e8
User & Date: js on 2011-02-05 14:47:57
Other Links: manifest | tags
Context
2011-02-05
15:15
Add support for Base64 encoding. check-in: 7459fabb87 user: js tags: trunk
14:47
Make sure we always have a return buffer in of_asprintf. check-in: a0ff17e12b user: js tags: trunk
14:44
Make sure that calling -[OFString init] creates a valid empty string. check-in: f7c9951937 user: js tags: trunk
Changes

Modified src/of_asprintf.m from [75df7de9af] to [8bf00513bd].

62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
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 (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;
483
484
485
486
487
488
489
490
491
492
493
494



495
496
497
498
499
500
501
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 = NULL;
	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;