ObjFW  Check-in [16786b4e7e]

Overview
Comment:Fix a bug in OFStream that was introduced by the new \0 behaviour.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 16786b4e7e812b828776dd9b6c149992f67893506e28e1c76d2052b0bb942308
User & Date: js on 2009-11-09 23:18:34
Other Links: manifest | tags
Context
2009-11-10
15:32
Improve -[compare:]. check-in: 6772512e3e user: js tags: trunk
2009-11-09
23:18
Fix a bug in OFStream that was introduced by the new \0 behaviour. check-in: 16786b4e7e user: js tags: trunk
23:08
Fix a forgotten rename. check-in: e94f3f9452 user: js tags: trunk
Changes

Modified src/OFStream.m from [da1c9ea74b] to [1e66caad30].

66
67
68
69
70
71
72
73

74
75
76
77
78
79
80
66
67
68
69
70
71
72

73
74
75
76
77
78
79
80







-
+







- (OFString*)readLine
{
	return [self readLineWithEncoding: OF_STRING_ENCODING_UTF_8];
}

- (OFString*)readLineWithEncoding: (enum of_string_encoding)encoding
{
	size_t i, len;
	size_t i, len, ret_len;
	char *ret_c, *tmp, *tmp2;
	OFString *ret;

	/* Look if there's a line or \0 in our cache */
	if (cache != NULL) {
		for (i = 0; i < cache_len; i++) {
			if (OF_UNLIKELY(cache[i] == '\n' ||
124
125
126
127
128
129
130

131
132
133

134
135
136
137
138
139
140
124
125
126
127
128
129
130
131
132
133

134
135
136
137
138
139
140
141







+


-
+







			[self freeMemory: tmp];
			@throw e;
		}

		/* Look if there's a newline or \0 */
		for (i = 0; i < len; i++) {
			if (OF_UNLIKELY(tmp[i] == '\n' || tmp[i] == '\0')) {
				ret_len = cache_len + i;
				@try {
					ret_c = [self
					    allocMemoryWithSize: cache_len + i];
					    allocMemoryWithSize: ret_len];
				} @catch (OFException *e) {
					[self freeMemory: tmp];
					@throw e;
				}
				if (cache != NULL)
					memcpy(ret_c, cache, cache_len);
				memcpy(ret_c + cache_len, tmp, i);
163
164
165
166
167
168
169
170

171
172
173
174
175
176
177
164
165
166
167
168
169
170

171
172
173
174
175
176
177
178







-
+







				}
				[self freeMemory: tmp];

				@try {
					ret = [OFString
					    stringWithCString: ret_c
						     encoding: encoding
						       length: cache_len + i];
						       length: ret_len];
				} @finally {
					[self freeMemory: ret_c];
				}
				return ret;
			}
		}