Software /
code /
prosody
Comparison
util-src/encodings.c @ 4273:7f789266b741
util.encodings: Check return values before proceeding
author | Paul Aurich <paul@darkrain42.org> |
---|---|
date | Sun, 22 May 2011 16:14:10 -0700 |
parent | 4272:0a4ce2086a88 |
child | 4302:bbb0bf0a09f5 |
comparison
equal
deleted
inserted
replaced
4272:0a4ce2086a88 | 4273:7f789266b741 |
---|---|
143 if (input_len >= 1024) { | 143 if (input_len >= 1024) { |
144 lua_pushnil(L); | 144 lua_pushnil(L); |
145 return 1; | 145 return 1; |
146 } | 146 } |
147 u_strFromUTF8(unprepped, 1024, &unprepped_len, input, input_len, &err); | 147 u_strFromUTF8(unprepped, 1024, &unprepped_len, input, input_len, &err); |
148 if (U_FAILURE(err)) { | |
149 luah_pushnil(L); | |
150 return 1; | |
151 } | |
148 prepped_len = usprep_prepare(profile, unprepped, unprepped_len, prepped, 1024, 0, NULL, &err); | 152 prepped_len = usprep_prepare(profile, unprepped, unprepped_len, prepped, 1024, 0, NULL, &err); |
149 if (U_FAILURE(err)) { | 153 if (U_FAILURE(err)) { |
150 lua_pushnil(L); | 154 lua_pushnil(L); |
151 return 1; | 155 return 1; |
152 } else { | 156 } else { |
153 u_strToUTF8(output, 1024, &output_len, prepped, prepped_len, &err); | 157 u_strToUTF8(output, 1024, &output_len, prepped, prepped_len, &err); |
154 if(output_len < 1024) | 158 if (U_SUCCESS(err) && output_len < 1024) |
155 lua_pushlstring(L, output, output_len); | 159 lua_pushlstring(L, output, output_len); |
156 else | 160 else |
157 lua_pushnil(L); | 161 lua_pushnil(L); |
158 return 1; | 162 return 1; |
159 } | 163 } |
256 UErrorCode err = U_ZERO_ERROR; | 260 UErrorCode err = U_ZERO_ERROR; |
257 UChar dest[1024]; | 261 UChar dest[1024]; |
258 char output[1024]; | 262 char output[1024]; |
259 | 263 |
260 u_strFromUTF8(ustr, 1024, &ulen, s, len, &err); | 264 u_strFromUTF8(ustr, 1024, &ulen, s, len, &err); |
265 if (U_FAILURE(err)) { | |
266 lua_pushnil(L); | |
267 return 1; | |
268 } | |
269 | |
261 dest_len = uidna_IDNToASCII(ustr, ulen, dest, 1024, UIDNA_USE_STD3_RULES, NULL, &err); | 270 dest_len = uidna_IDNToASCII(ustr, ulen, dest, 1024, UIDNA_USE_STD3_RULES, NULL, &err); |
262 if (U_FAILURE(err)) { | 271 if (U_FAILURE(err)) { |
263 lua_pushnil(L); | 272 lua_pushnil(L); |
264 return 1; | 273 return 1; |
265 } else { | 274 } else { |
266 u_strToUTF8(output, 1024, &output_len, dest, dest_len, &err); | 275 u_strToUTF8(output, 1024, &output_len, dest, dest_len, &err); |
267 if(output_len < 1024) | 276 if (U_SUCCESS(err) && output_len < 1024) |
268 lua_pushlstring(L, output, output_len); | 277 lua_pushlstring(L, output, output_len); |
269 else | 278 else |
270 lua_pushnil(L); | 279 lua_pushnil(L); |
271 return 1; | 280 return 1; |
272 } | 281 } |
281 UErrorCode err = U_ZERO_ERROR; | 290 UErrorCode err = U_ZERO_ERROR; |
282 UChar dest[1024]; | 291 UChar dest[1024]; |
283 char output[1024]; | 292 char output[1024]; |
284 | 293 |
285 u_strFromUTF8(ustr, 1024, &ulen, s, len, &err); | 294 u_strFromUTF8(ustr, 1024, &ulen, s, len, &err); |
295 if (U_FAILURE(err)) { | |
296 lua_pushnil(L); | |
297 return 1; | |
298 } | |
299 | |
286 dest_len = uidna_IDNToUnicode(ustr, ulen, dest, 1024, UIDNA_USE_STD3_RULES, NULL, &err); | 300 dest_len = uidna_IDNToUnicode(ustr, ulen, dest, 1024, UIDNA_USE_STD3_RULES, NULL, &err); |
287 if (U_FAILURE(err)) { | 301 if (U_FAILURE(err)) { |
288 lua_pushnil(L); | 302 lua_pushnil(L); |
289 return 1; | 303 return 1; |
290 } else { | 304 } else { |
291 u_strToUTF8(output, 1024, &output_len, dest, dest_len, &err); | 305 u_strToUTF8(output, 1024, &output_len, dest, dest_len, &err); |
292 if(output_len < 1024) | 306 if (U_SUCCESS(err) && output_len < 1024) |
293 lua_pushlstring(L, output, output_len); | 307 lua_pushlstring(L, output, output_len); |
294 else | 308 else |
295 lua_pushnil(L); | 309 lua_pushnil(L); |
296 return 1; | 310 return 1; |
297 } | 311 } |