ObjFW  Check-in [dc17a614e8]

Overview
Comment:Replace a few asserts with OF_ENSURE / OBJC_ERROR.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: dc17a614e8caf5f6b9306309c287ac3599aa3e05f176d5461522198e474030d1
User & Date: js on 2013-06-17 08:54:17
Other Links: manifest | tags
Context
2013-06-17
09:36
OFString: Fix standardize_path(). check-in: 379d75e1bc user: js tags: trunk
08:54
Replace a few asserts with OF_ENSURE / OBJC_ERROR. check-in: dc17a614e8 user: js tags: trunk
08:44
Rename -[OFDataArray readDataArrayWithSize:]. check-in: eceebefeab user: js tags: trunk
Changes

Modified src/OFTCPSocket.m from [17c2cc5542] to [b00741c4c9].

21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
21
22
23
24
25
26
27


28
29
30
31
32
33
34







-
-








#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <unistd.h>

#include <assert.h>

#ifdef HAVE_NETINET_IN_H
# include <netinet/in.h>
#endif
#ifdef HAVE_ARPA_INET_H
# include <arpa/inet.h>
#endif
#ifdef HAVE_NETDB_H
807
808
809
810
811
812
813
814

815
816
817
818
819
820
821
805
806
807
808
809
810
811

812
813
814
815
816
817
818
819







-
+







	} @finally {
		[mutex unlock];
	}
# endif
#endif

	/* Get rid of a warning, never reached anyway */
	assert(0);
	OF_ENSURE(0);
}

- (bool)isListening
{
	return _listening;
}

Modified src/runtime/class.m from [6e9f617165] to [179d6825a3].

16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
16
17
18
19
20
21
22


23
24
25
26
27
28
29







-
-








#include "config.h"

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <assert.h>

#import "runtime.h"
#import "runtime-private.h"

static struct objc_hashtable *classes = NULL;
static Class *load_queue = NULL;
static size_t load_queue_cnt = 0;
static struct objc_sparsearray *empty_dtable = NULL;

Modified src/runtime/hashtable.m from [3f8cbae000] to [7a48f16f9e].

17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
17
18
19
20
21
22
23


24
25
26
27
28
29
30







-
-







#include "config.h"

#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>

#include <assert.h>

#import "runtime.h"
#import "runtime-private.h"

uint32_t
objc_hash_string(const char *str)
{
	uint32_t hash = 0;
70
71
72
73
74
75
76

77


78
79
80
81
82
83


84
85
86
87
88
89
90
68
69
70
71
72
73
74
75

76
77
78
79
80
81
82

83
84
85
86
87
88
89
90
91







+
-
+
+





-
+
+







static void
insert(struct objc_hashtable *h, const char *key, const void *obj)
{
	uint32_t i, hash, last;
	struct objc_hashtable_bucket *bucket;

	hash = objc_hash_string(key);

	assert(h->count + 1 <= UINT32_MAX / 4);
	if (h->count + 1 > UINT32_MAX / 4)
		OBJC_ERROR("Integer overflow!");

	if ((h->count + 1) * 4 / (h->last_idx + 1) >= 3) {
		struct objc_hashtable_bucket **ndata;
		uint32_t nsize = (h->last_idx + 1) * 2;

		assert(nsize > 0);
		if (nsize == 0)
			OBJC_ERROR("Integer overflow!");

		ndata = malloc(nsize * sizeof(struct objc_hashtable_bucket*));
		if (ndata == NULL)
			OBJC_ERROR("Not enough memory to insert into hash "
			    "table!");

		for (i = 0; i < nsize; i++)

Modified tests/OFHTTPClientTests.m from [7b9b64988c] to [20876eb150].

16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
16
17
18
19
20
21
22


23
24
25
26
27
28
29







-
-








#include "config.h"

#include <stdlib.h>
#include <string.h>
#include <time.h>

#include <assert.h>

#import "OFHTTPClient.h"
#import "OFHTTPRequest.h"
#import "OFHTTPRequestReply.h"
#import "OFString.h"
#import "OFTCPSocket.h"
#import "OFThread.h"
#import "OFCondition.h"
60
61
62
63
64
65
66
67

68
69
70
71

72
73
74

75
76
77

78
79
80
81
82
83
84
58
59
60
61
62
63
64

65
66
67
68

69
70
71

72
73
74

75
76
77
78
79
80
81
82







-
+



-
+


-
+


-
+








	[cond signal];
	[cond unlock];

	client = [listener accept];

	if (![[client readLine] isEqual: @"GET /foo HTTP/1.1"])
		assert(0);
		OF_ENSURE(0);

	if (![[client readLine] isEqual:
	    [OFString stringWithFormat: @"Host: 127.0.0.1:%" @PRIu16, port]])
		assert(0);
		OF_ENSURE(0);

	if (![[client readLine] hasPrefix: @"User-Agent:"])
		assert(0);
		OF_ENSURE(0);

	if (![[client readLine] isEqual: @""])
		assert(0);
		OF_ENSURE(0);

	[client writeString: @"HTTP/1.0 200 OK\r\n"
			     @"cONTeNT-lENgTH: 7\r\n"
			     @"\r\n"
			     @"foo\n"
			     @"bar"];
	[client close];