ObjFW  Check-in [51dff30395]

Overview
Comment:Check for more invalid UTF-8 byte sequences.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 51dff303958782f82b9db633ef1a78313ed83d5210d3fbfc5f4cf4c91bd2e099
User & Date: js on 2011-07-09 00:00:44
Other Links: manifest | tags
Context
2011-07-09
03:10
Emphasize that -[readNBytes:intoBuffer:] reads at most n bytes. check-in: e1285e3ba9 user: js tags: trunk
00:00
Check for more invalid UTF-8 byte sequences. check-in: 51dff30395 user: js tags: trunk
2011-07-08
21:26
Adjust TableGenerator to (not so) recent style changes. check-in: 30cdebfa2a user: js tags: trunk
Changes

Modified src/OFString.m from [518f441548] to [ee8d4c3fc0].

97
98
99
100
101
102
103






104
105
106
107
108
109
110
		isUTF8 = 1;

		/* We're missing a start byte here */
		if (OF_UNLIKELY(!(string[i] & 0x40))) {
			madvise((void*)string, length, MADV_NORMAL);
			return -1;
		}







		/* We have at minimum a 2 byte character -> check next byte */
		if (OF_UNLIKELY(length <= i + 1 ||
		    (string[i + 1] & 0xC0) != 0x80)) {
			madvise((void*)string, length, MADV_NORMAL);
			return -1;
		}







>
>
>
>
>
>







97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
		isUTF8 = 1;

		/* We're missing a start byte here */
		if (OF_UNLIKELY(!(string[i] & 0x40))) {
			madvise((void*)string, length, MADV_NORMAL);
			return -1;
		}

		/* 2 byte sequences for code points 0 - 127 are forbidden */
		if (OF_UNLIKELY((string[i] & 0x7E) == 0x40)) {
			madvise((void*)string, length, MADV_NORMAL);
			return -1;
		}

		/* We have at minimum a 2 byte character -> check next byte */
		if (OF_UNLIKELY(length <= i + 1 ||
		    (string[i + 1] & 0xC0) != 0x80)) {
			madvise((void*)string, length, MADV_NORMAL);
			return -1;
		}