ObjFW  Check-in [1c2e0d4711]

Overview
Comment:Fix missing terminating char and glibc bug.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 1c2e0d471185f8d8e65c2f825044f980d87367fe871ab107e14e171e03de4a12
User & Date: js on 2008-09-14 17:59:43
Other Links: manifest | tags
Context
2008-09-14
18:17
Fix append for OFWideString. check-in: bcdf93590c user: js tags: trunk
17:59
Fix missing terminating char and glibc bug. check-in: 1c2e0d4711 user: js tags: trunk
17:50
D'oh, wrong variable(s). check-in: 08e3f30363 user: js tags: trunk
Changes

Modified src/OFString.m from [52bd147dc6] to [1c1ae2a28e].

28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
{
	if ((self = [super init])) {
		if (str == NULL) {
			length = 0;
			string = NULL;
		} else {
			length = strlen(str);
			if ((string = [self getMem: length]) == NULL)
				return NULL;
			memcpy(string, str, length);
		}
	}
	return self;
}

- (char*)cString
{







|

|







28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
{
	if ((self = [super init])) {
		if (str == NULL) {
			length = 0;
			string = NULL;
		} else {
			length = strlen(str);
			if ((string = [self getMem: length + 1]) == NULL)
				return NULL;
			memcpy(string, str, length + 1);
		}
	}
	return self;
}

- (char*)cString
{
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
		length = 0;
		string = NULL;

		return self;
	}

	newlen = strlen(str);
	if ((newstr = [self getMem: newlen]) == NULL)
		return nil;
	memcpy(newstr, str, newlen);

	if (string != NULL)
		[self freeMem: string];

	length = newlen;
	string = newstr;








|

|







61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
		length = 0;
		string = NULL;

		return self;
	}

	newlen = strlen(str);
	if ((newstr = [self getMem: newlen + 1]) == NULL)
		return nil;
	memcpy(newstr, str, newlen + 1);

	if (string != NULL)
		[self freeMem: string];

	length = newlen;
	string = newstr;

95
96
97
98
99
100
101
102
103
104
105
106
107

108
109
110
111
	newlen = length + strlength;

	/* FIXME: Add error handling */
	if ((newstr = [self resizeMem: string
			       toSize: newlen + 1]) == NULL)
		return nil;

	string = newstr;

	memcpy(string + length, str, strlength);
	string[newlen] = '\0';

	length = newlen;


	return self;
}
@end







<
<
|
<


>




95
96
97
98
99
100
101


102

103
104
105
106
107
108
109
	newlen = length + strlength;

	/* FIXME: Add error handling */
	if ((newstr = [self resizeMem: string
			       toSize: newlen + 1]) == NULL)
		return nil;



	memcpy(newstr + length, str, strlength + 1);


	length = newlen;
	string = newstr;

	return self;
}
@end

Modified src/OFWideString.m from [3d87632f9d] to [9ef8d3d479].

29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
{
	if ((self = [super init])) {
		if (wstr == NULL) {
			length = 0;
			wstring = NULL;
		} else {
			length = wcslen(wstr);
			if ((wstring =
			    [self getMem: length * sizeof(wchar_t)]) == NULL)
				return NULL;
			memcpy(wstring, wstr, length * sizeof(wchar_t));
		}
	}
	return self;
}

- (wchar_t*)wcString
{







|
|

|







29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
{
	if ((self = [super init])) {
		if (wstr == NULL) {
			length = 0;
			wstring = NULL;
		} else {
			length = wcslen(wstr);
			if (NULL == (wstring =
			    [self getMem: (length + 1) * sizeof(wchar_t)]))
				return NULL;
			memcpy(wstring, wstr, (length + 1) * sizeof(wchar_t));
		}
	}
	return self;
}

- (wchar_t*)wcString
{
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
		length = 0;
		wstring = NULL;

		return self;
	}

	newlen = wcslen(wstr);
	if ((newstr = [self getMem: newlen * sizeof(wchar_t)]) == NULL)
		return nil;
	memcpy(newstr, wstr, newlen * sizeof(wchar_t));

	if (wstring != NULL)
		[self freeMem: wstring];

	length = newlen;
	wstring = newstr;








|

|







63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
		length = 0;
		wstring = NULL;

		return self;
	}

	newlen = wcslen(wstr);
	if ((newstr = [self getMem: (newlen + 1) * sizeof(wchar_t)]) == NULL)
		return nil;
	memcpy(newstr, wstr, (newlen + 1) * sizeof(wchar_t));

	if (wstring != NULL)
		[self freeMem: wstring];

	length = newlen;
	wstring = newstr;

94
95
96
97
98
99
100
101

102
103
104
105
106
107
108
109
110

111
112
113
114
		return [self setTo: wstr];

	strlength = wcslen(wstr);
	newlen = length + strlength;

	/* FIXME: Add error handling */
	if ((newstr = [self resizeMem: wstring
			       toSize: newlen  * sizeof(wchar_t) + 2]) == NULL)

		return nil;

	wstring = newstr;

	memcpy(wstring + length * sizeof(wchar_t), wstr,
	    strlength * sizeof(wchar_t));
	wstring[newlen] = '\0';

	length = newlen;


	return self;
}
@end







|
>


<
<
|
|
<


>




94
95
96
97
98
99
100
101
102
103
104


105
106

107
108
109
110
111
112
113
		return [self setTo: wstr];

	strlength = wcslen(wstr);
	newlen = length + strlength;

	/* FIXME: Add error handling */
	if ((newstr = [self resizeMem: wstring
			       toSize: (newlen + 1 ) * sizeof(wchar_t)]) == 
	    NULL)
		return nil;



	memcpy(newstr + length * sizeof(wchar_t), wstr,
	    (strlength + 1) * sizeof(wchar_t));


	length = newlen;
	wstring = newstr;

	return self;
}
@end

Modified tests/OFWideString/OFWideString.m from [b584f40ba9] to [aeb6f6f145].

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*
 * Copyright (c) 2008
 *   Jonathan Schleifer <js@webkeks.org>
 *
 * All rights reserved.
 *
 * This file is part of libobjfw. It may be distributed under the terms of the
 * Q Public License 1.0, which can be found in the file LICENSE included in
 * the packaging of this file.
 */

#import <stdio.h>
#import <wchar.h>

#import "OFWideString.h"

/* TODO: Do real checks */

int
main()
{
	OFWideString *s1 = [OFWideString new: L"foo"];
	OFWideString *s2 = [[OFWideString alloc] init: L""];
	OFWideString *s3;
	OFWideString *s4 = [OFWideString new];

	printf("%p\n", [s2 append: L"bar"]);
	s3 = [s1 clone];

	[s4 setTo: [s2 wcString]];

	wprintf(L"s1 = %S\n", [s1 wcString]);
	wprintf(L"s2 = %S\n", [s2 wcString]);
	wprintf(L"s3 = %S\n", [s3 wcString]);
	wprintf(L"s4 = %S\n", [s4 wcString]);

	[s1 append: [s2 wcString]];
	wprintf(L"s1 append s2 = %S\n", [s1 wcString]);
	wprintf(L"strlen(s1) = %zd, [s1 length] = %zd\n",
	    wcslen([s1 wcString]), [s1 length]);
	[s1 free];
	[s2 free];
	[s3 free];
	[s4 free];

	return 0;
}











|














|











|








1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*
 * Copyright (c) 2008
 *   Jonathan Schleifer <js@webkeks.org>
 *
 * All rights reserved.
 *
 * This file is part of libobjfw. It may be distributed under the terms of the
 * Q Public License 1.0, which can be found in the file LICENSE included in
 * the packaging of this file.
 */

#define _ISOC99_SOURCE
#import <wchar.h>

#import "OFWideString.h"

/* TODO: Do real checks */

int
main()
{
	OFWideString *s1 = [OFWideString new: L"foo"];
	OFWideString *s2 = [[OFWideString alloc] init: L""];
	OFWideString *s3;
	OFWideString *s4 = [OFWideString new];

	[s2 append: L"bar"];
	s3 = [s1 clone];

	[s4 setTo: [s2 wcString]];

	wprintf(L"s1 = %S\n", [s1 wcString]);
	wprintf(L"s2 = %S\n", [s2 wcString]);
	wprintf(L"s3 = %S\n", [s3 wcString]);
	wprintf(L"s4 = %S\n", [s4 wcString]);

	[s1 append: [s2 wcString]];
	wprintf(L"s1 append s2 = %S\n", [s1 wcString]);
	wprintf(L"wcslen(s1) = %zd, [s1 length] = %zd\n",
	    wcslen([s1 wcString]), [s1 length]);
	[s1 free];
	[s2 free];
	[s3 free];
	[s4 free];

	return 0;
}