summaryrefslogtreecommitdiff
blob: 8efedc01e4aa5a710a98db76f3057a0f27b42676 (plain)
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
48
49
50
51
52
53
54
55
56
57
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
beecrypt's c++ api uses jchar arrays for strings, while ICU 59 expects
char16_t type

In practice these both seem to be defined as short int on amd64 so it
might be okay to just reinterpret_cast them? There's probably no easy
way out on a platform where char16_t won't match jchar

Patch by Valeriy Malov <jazzvoid@gmail.com>
https://bugs.gentoo.org/618676

--- a/c++/io/DataInputStream.cxx
+++ b/c++/io/DataInputStream.cxx
@@ -201,7 +201,7 @@ String DataInputStream::readUTF() throw (IOException)
 		jchar* buffer = new jchar[ulen+1];
 
 		status = U_ZERO_ERROR;
-		ucnv_toUChars(_utf, buffer, ulen+1, (const char*) data, (jint) utflen, &status);
+		ucnv_toUChars(_utf, reinterpret_cast<UChar*>(buffer), ulen+1, (const char*) data, (jint) utflen, &status);
 
 		delete[] data;
 
@@ -232,7 +232,7 @@ String DataInputStream::readLine() throw (IOException)
 
 	array<jchar> target_buffer(80);
 	jint         target_offset = 0;
-	      UChar* target = target_buffer.data();
+		  UChar* target = reinterpret_cast<UChar*>(target_buffer.data());
 	const UChar* target_limit = target+1;
 	      char  source_buffer[MAX_BYTES_PER_CHARACTER];
 	const char* source = source_buffer;
--- a/c++/io/DataOutputStream.cxx
+++ b/c++/io/DataOutputStream.cxx
@@ -187,7 +187,7 @@ void DataOutputStream::writeUTF(const String& str) throw (IOException)
 	const array<jchar>& src = str.toCharArray();
 
 	// the expected status code here is U_BUFFER_OVERFLOW_ERROR
-	jint need = ucnv_fromUChars(_utf, 0, 0, src.data(), src.size(), &status);
+	jint need = ucnv_fromUChars(_utf, 0, 0, reinterpret_cast<const UChar*>(src.data()), src.size(), &status);
 	if (U_FAILURE(status))
 		if (status != U_BUFFER_OVERFLOW_ERROR)
 			throw IOException("ucnv_fromUChars failed");
@@ -200,7 +200,7 @@ void DataOutputStream::writeUTF(const String& str) throw (IOException)
 	status = U_ZERO_ERROR;
 
 	// the expected status code here is U_STRING_NOT_TERMINATED_WARNING
-	ucnv_fromUChars(_utf, (char*) buffer, need, src.data(), src.size(), &status);
+	ucnv_fromUChars(_utf, (char*) buffer, need, reinterpret_cast<const UChar*>(src.data()), src.size(), &status);
 	if (status != U_STRING_NOT_TERMINATED_WARNING)
 	{
 		delete[] buffer;
--- a/c++/io/PrintStream.cxx
+++ b/c++/io/PrintStream.cxx
@@ -191,7 +191,7 @@ void PrintStream::print(jchar ch) throw ()
 			UErrorCode status = U_ZERO_ERROR;
 
 			// do conversion of one character
-			size_t used = ucnv_fromUChars(_loc, buffer, 8, &ch, 1, &status);
+			size_t used = ucnv_fromUChars(_loc, buffer, 8, reinterpret_cast<UChar*>(&ch), 1, &status);
 			if (U_FAILURE(status))
 				throw IOException("failure in ucnv_fromUChars");
 
@@ -268,14 +268,14 @@ void PrintStream::print(jlong x) throw ()
 
 void PrintStream::print(const array<jchar>& chars) throw ()
 {
-	print(chars.data(), chars.size());
+	print(reinterpret_cast<const UChar*>(chars.data()), chars.size());
 }
 
 void PrintStream::print(const String& str) throw ()
 {
 	const array<jchar>& tmp = str.toCharArray();
 
-	print(tmp.data(), tmp.size());
+	print(reinterpret_cast<const UChar*>(tmp.data()), tmp.size());
 }
 
 void PrintStream::println() throw ()
--- a/c++/lang/String.cxx
+++ b/c++/lang/String.cxx
@@ -33,6 +33,8 @@ using namespace beecrypt::lang;
 #include <unicode/ustdio.h>
 #include <unicode/ustring.h>
 
+static_assert(sizeof(jchar) == sizeof(UChar), "jchar and UChar sizes mismatch");
+
 String::String(array<jchar>& swapWith)
 {
 	assert(swapWith.size() <= Integer::MAX_VALUE);
@@ -56,7 +58,7 @@ String::String()
 
 String::String(char c) : _value(1)
 {
-	u_charsToUChars(&c, _value.data(), 1);
+	u_charsToUChars(&c, reinterpret_cast<UChar*>(_value.data()), 1);
 }
 
 String::String(jchar c) : _value(&c, 1)
@@ -67,7 +69,7 @@ String::String(const char* value) : _value(::strlen(value))
 {
 	assert(_value.size() <= Integer::MAX_VALUE);
 
-	u_charsToUChars(value, _value.data(), _value.size());
+	u_charsToUChars(value, reinterpret_cast<UChar*>(_value.data()), _value.size());
 }
 
 String::String(const jchar* value, int offset, int length) : _value(value+offset, length)
@@ -449,7 +451,7 @@ std::ostream& beecrypt::lang::operator<<(std::ostream& stream, const String& str
 		if (U_FAILURE(status))
 			throw RuntimeException("ucnv_open failed");
 
-		int need = ucnv_fromUChars(loc, 0, 0, src.data(), src.size(), &status);
+		int need = ucnv_fromUChars(loc, 0, 0, reinterpret_cast<const UChar*>(src.data()), src.size(), &status);
 		if (U_FAILURE(status))
 			if (status != U_BUFFER_OVERFLOW_ERROR)
 				throw RuntimeException("ucnv_fromUChars failed");
@@ -458,7 +460,7 @@ std::ostream& beecrypt::lang::operator<<(std::ostream& stream, const String& str
 
 		status = U_ZERO_ERROR;
 
-		ucnv_fromUChars(loc, out, need+1, src.data(), src.size(), &status);
+		ucnv_fromUChars(loc, out, need+1, reinterpret_cast<const UChar*>(src.data()), src.size(), &status);
 		if (U_FAILURE(status))
 			throw RuntimeException("ucnv_fromUChars failed");
 
--- a/c++/lang/StringBuffer.cxx
+++ b/c++/lang/StringBuffer.cxx
@@ -35,7 +35,7 @@ StringBuffer::StringBuffer() : _buffer(16)
 
 StringBuffer::StringBuffer(const char* s) : _buffer(16 + strlen(s))
 {
-	u_charsToUChars(s, _buffer.data(), _used = strlen(s));
+	u_charsToUChars(s, reinterpret_cast<UChar*>(_buffer.data()), _used = strlen(s));
 }
 
 StringBuffer::StringBuffer(const String& s) : _buffer(16 + s._value.size())
@@ -53,7 +53,7 @@ StringBuffer& StringBuffer::append(char c)
 	synchronized (this)
 	{
 		core_ensureCapacity(_used+1);
-		u_charsToUChars(&c, _buffer.data() + _used++, 1);
+		u_charsToUChars(&c, reinterpret_cast<UChar*>(_buffer.data() + _used++), 1);
 	}
 	return *this;
 }
@@ -88,7 +88,7 @@ StringBuffer& StringBuffer::append(const char* s)
 		jint need = strlen(s);
 
 		core_ensureCapacity(_used + need);
-		u_charsToUChars(s, _buffer.data() + _used, need);
+		u_charsToUChars(s, reinterpret_cast<UChar*>(_buffer.data() + _used), need);
 
 		_used += need;
 	}
--- a/c++/lang/StringBuilder.cxx
+++ b/c++/lang/StringBuilder.cxx
@@ -38,7 +38,7 @@ StringBuilder::StringBuilder() : _buffer(16)
 
 StringBuilder::StringBuilder(const char* s) : _buffer(16 + strlen(s))
 {
-	u_charsToUChars(s, _buffer.data(), _used = strlen(s));
+	u_charsToUChars(s, reinterpret_cast<UChar*>(_buffer.data()), _used = strlen(s));
 }
 
 StringBuilder::StringBuilder(const String& s) : _buffer(16 + s._value.size())
@@ -55,7 +55,7 @@ StringBuilder& StringBuilder::append(char c)
 {
 	ensureCapacity(_used+1);
 
-	u_charsToUChars(&c, _buffer.data() + _used++, 1);
+	u_charsToUChars(&c, reinterpret_cast<UChar*>(_buffer.data() + _used++), 1);
 
 	return *this;
 }
@@ -97,7 +97,7 @@ StringBuilder& StringBuilder::append(const char* s)
 
 	ensureCapacity(_used + need);
 
-	u_charsToUChars(s, _buffer.data() + _used, need);
+	u_charsToUChars(s, reinterpret_cast<UChar*>(_buffer.data() + _used), need);
 
 	_used += need;
 
--- a/c++/security/Provider.cxx
+++ b/c++/security/Provider.cxx
@@ -90,7 +90,7 @@ Object* Provider::setProperty(const String& key, const String& value)
 
 			UErrorCode status = U_ZERO_ERROR;
 
-			ucnv_fromUChars(_conv, symname, 1024, src.data(), src.size(), &status);
+			ucnv_fromUChars(_conv, symname, 1024, reinterpret_cast<const UChar*>(src.data()), src.size(), &status);
 
 			if (status != U_ZERO_ERROR)
 					throw RuntimeException("error in ucnv_fromUChars");
--- a/c++/security/Security.cxx
+++ b/c++/security/Security.cxx
@@ -104,7 +104,7 @@ void Security::initialize()
 
 					const array<jchar>& src = value->toCharArray();
 
-					int need = ucnv_fromUChars(_loc, 0, 0, src.data(), src.size(), &status);
+					int need = ucnv_fromUChars(_loc, 0, 0, reinterpret_cast<const UChar*>(src.data()), src.size(), &status);
 					if (U_FAILURE(status))
 						if (status != U_BUFFER_OVERFLOW_ERROR)
 							throw RuntimeException("ucnv_fromUChars failed");
@@ -112,7 +112,7 @@ void Security::initialize()
 					char* shared_library = new char[need+1];
 
 					status = U_ZERO_ERROR;
-					ucnv_fromUChars(_loc, shared_library, need+1, src.data(), src.size(), &status);
+					ucnv_fromUChars(_loc, shared_library, need+1, reinterpret_cast<const UChar*>(src.data()), src.size(), &status);
 					if (U_FAILURE(status))
 						throw RuntimeException("ucnv_fromUChars failed");