ObjFW  Diff

Differences From Artifact [784bf1ffb2]:

To Artifact [f65a681bbc]:


26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#import "OFOutOfMemoryException.h"

static struct of_huffman_tree *
newTree(void)
{
	struct of_huffman_tree *tree;

	if ((tree = malloc(sizeof(*tree))) == NULL)
		@throw [OFOutOfMemoryException
		    exceptionWithRequestedSize: sizeof(*tree)];

	tree->leaves[0] = tree->leaves[1] = NULL;
	tree->value = 0xFFFF;

	return tree;
}

static void







|
<
<
<







26
27
28
29
30
31
32
33



34
35
36
37
38
39
40
#import "OFOutOfMemoryException.h"

static struct of_huffman_tree *
newTree(void)
{
	struct of_huffman_tree *tree;

	tree = of_malloc(1, sizeof(*tree));



	tree->leaves[0] = tree->leaves[1] = NULL;
	tree->value = 0xFFFF;

	return tree;
}

static void
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
	uint_fast8_t maxBit = 0;

	@try {
		for (uint16_t i = 0; i < count; i++) {
			uint_fast8_t length = lengths[i];

			if OF_UNLIKELY (length > maxBit) {
				size_t size = (length + 1) * sizeof(uint16_t);
				uint16_t *new;

				if ((new = realloc(lengthCount, size)) == NULL)
					@throw [OFOutOfMemoryException
					    exceptionWithRequestedSize: size];

				lengthCount = new;

				if ((new = realloc(nextCode, size)) == NULL)
					@throw [OFOutOfMemoryException
					    exceptionWithRequestedSize: size];

				nextCode = new;

				for (uint_fast8_t j = maxBit + 1; j <= length;
				    j++) {
					lengthCount[j] = 0;
					nextCode[j] = 0;
				}








<
<
<
<
<
<
<
|
|
|
<
<
|
<







65
66
67
68
69
70
71







72
73
74


75

76
77
78
79
80
81
82
	uint_fast8_t maxBit = 0;

	@try {
		for (uint16_t i = 0; i < count; i++) {
			uint_fast8_t length = lengths[i];

			if OF_UNLIKELY (length > maxBit) {







				lengthCount = of_realloc(lengthCount,
				    length + 1, sizeof(uint16_t));
				nextCode = of_realloc(nextCode,


				    length + 1, sizeof(uint16_t));


				for (uint_fast8_t j = maxBit + 1; j <= length;
				    j++) {
					lengthCount[j] = 0;
					nextCode[j] = 0;
				}