ObjFW  Diff

Differences From Artifact [3466f7d906]:

  • File src/of_asprintf.m — part of check-in [5eada9f7b0] at 2013-11-23 03:24:43 on branch trunk — of_asprintf: Change %C to %k.

    In Cocoa, %C means unichar, which is unsigned short and thus compilers
    expect %C to be unichar when the language is set to ObjC. It would be
    hard to let compilers detect whether %C should be unichar or
    of_unichar_t, especially when mixing ObjFW and Cocoa code, thus the
    change to %k. (user: js, size: 12902) [annotate] [blame] [check-ins using]

To Artifact [0045836345]:


24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <stdbool.h>
#include <wchar.h>

#include <sys/types.h>

#import "OFString.h"

#import "OFInvalidEncodingException.h"

#import "asprintf.h"
#import "autorelease.h"
#import "macros.h"

#define MAX_SUBFORMAT_LEN 64

struct context {







<
<







24
25
26
27
28
29
30


31
32
33
34
35
36
37
#include <stdbool.h>
#include <wchar.h>

#include <sys/types.h>

#import "OFString.h"



#import "asprintf.h"
#import "autorelease.h"
#import "macros.h"

#define MAX_SUBFORMAT_LEN 64

struct context {
327
328
329
330
331
332
333
334
335
336
337
338





































339
340
341
342
343
344
345

		{
			char buffer[5];
			size_t len = of_string_utf8_encode(
			    va_arg(ctx->arguments, of_unichar_t), buffer);

			if (len == 0)
				@throw [OFInvalidEncodingException exception];

			buffer[len] = 0;
			tmpLen = asprintf(&tmp, ctx->subformat, buffer);
		}






































		break;
	case 'd':
	case 'i':
		switch (ctx->lengthModifier) {
		case LENGTH_MODIFIER_NONE:
		case LENGTH_MODIFIER_HH:







|




>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380

		{
			char buffer[5];
			size_t len = of_string_utf8_encode(
			    va_arg(ctx->arguments, of_unichar_t), buffer);

			if (len == 0)
				return false;

			buffer[len] = 0;
			tmpLen = asprintf(&tmp, ctx->subformat, buffer);
		}

		break;
	case 'K':
		if (ctx->lengthModifier != LENGTH_MODIFIER_NONE)
			return false;

		ctx->subformat[ctx->subformatLen - 1] = 's';

		{
			const of_unichar_t *arg =
			    va_arg(ctx->arguments, const of_unichar_t*);
			size_t i, j, len = of_string_utf32_length(arg);
			char *buffer;

			if (SIZE_MAX / 4 < len || (SIZE_MAX / 4) - len < 1)
				return false;

			if ((buffer = malloc((len * 4) + 1)) == NULL)
				return false;

			for (i = j = 0; i < len; i++) {
				size_t clen = of_string_utf8_encode(arg[i],
				    buffer + j);

				if (clen == 0) {
					free(buffer);
					return false;
				}

				j += clen;
			}
			buffer[j] = 0;

			tmpLen = asprintf(&tmp, ctx->subformat, buffer);

			free(buffer);
		}

		break;
	case 'd':
	case 'i':
		switch (ctx->lengthModifier) {
		case LENGTH_MODIFIER_NONE:
		case LENGTH_MODIFIER_HH: