comparison src/mule-ccl.c @ 2829:714b354cef67

[xemacs-hg @ 2005-06-26 18:42:21 by aidan] Prevent Mule-CCL crashing XEmacs on an invalid charset id.
author aidan
date Sun, 26 Jun 2005 18:42:23 +0000
parents cf4a5f5e87ea
children d7505a1267a4
comparison
equal deleted inserted replaced
2828:a25c824ed558 2829:714b354cef67
824 else \ 824 else \
825 CCL_SUSPEND (CCL_STAT_SUSPEND_BY_SRC); \ 825 CCL_SUSPEND (CCL_STAT_SUSPEND_BY_SRC); \
826 } \ 826 } \
827 } while (0) 827 } while (0)
828 828
829 #define POSSIBLE_LEADING_BYTE_P(lb) \
830 ((leading_byte > MIN_LEADING_BYTE) && \
831 (leading_byte - MIN_LEADING_BYTE) < NUM_LEADING_BYTES)
829 832
830 /* Set C to the character code made from CHARSET and CODE. This is 833 /* Set C to the character code made from CHARSET and CODE. This is
831 like make_ichar but check the validity of CHARSET and CODE. If they 834 like make_ichar but check the validity of CHARSET and CODE. If they
832 are not valid, set C to (CODE & 0xFF) because that is usually the 835 are not valid, set C to (CODE & 0xFF) because that is usually the
833 case that CCL_ReadMultibyteChar2 read an invalid code and it set 836 case that CCL_ReadMultibyteChar2 read an invalid code and it set
1293 { 1296 {
1294 /* ASCII */ 1297 /* ASCII */
1295 reg[rrr] = i; 1298 reg[rrr] = i;
1296 reg[RRR] = LEADING_BYTE_ASCII; 1299 reg[RRR] = LEADING_BYTE_ASCII;
1297 } 1300 }
1301 /* Previously, these next two elses were reversed in order,
1302 which should have worked fine, but is more fragile than
1303 this order. */
1304 else if (LEADING_BYTE_CONTROL_1 == i)
1305 {
1306 if (src >= src_end)
1307 goto ccl_read_multibyte_character_suspend;
1308 reg[RRR] = i;
1309 reg[rrr] = (*src++ - 0xA0);
1310 }
1298 else if (i <= MAX_LEADING_BYTE_OFFICIAL_1) 1311 else if (i <= MAX_LEADING_BYTE_OFFICIAL_1)
1299 { 1312 {
1300 if (src >= src_end) 1313 if (src >= src_end)
1301 goto ccl_read_multibyte_character_suspend; 1314 goto ccl_read_multibyte_character_suspend;
1302 reg[RRR] = i; 1315 reg[RRR] = i;
1303 reg[rrr] = (*src++ & 0x7F); 1316 reg[rrr] = (*src++ & 0x7F);
1304 }
1305 else if (LEADING_BYTE_CONTROL_1 == i)
1306 {
1307 if (src >= src_end)
1308 goto ccl_read_multibyte_character_suspend;
1309 reg[RRR] = i;
1310 reg[rrr] = (*src++ - 0xA0);
1311 } 1317 }
1312 else if (i <= MAX_LEADING_BYTE_OFFICIAL_2) 1318 else if (i <= MAX_LEADING_BYTE_OFFICIAL_2)
1313 { 1319 {
1314 if ((src + 1) >= src_end) 1320 if ((src + 1) >= src_end)
1315 goto ccl_read_multibyte_character_suspend; 1321 goto ccl_read_multibyte_character_suspend;
1354 1360
1355 break; 1361 break;
1356 1362
1357 case CCL_WriteMultibyteChar2: 1363 case CCL_WriteMultibyteChar2:
1358 i = reg[RRR]; /* charset */ 1364 i = reg[RRR]; /* charset */
1359 if (i == LEADING_BYTE_ASCII || i == LEADING_BYTE_CONTROL_1) 1365 if (i == LEADING_BYTE_ASCII)
1360 i = reg[rrr] & 0xFF; 1366 i = reg[rrr] & 0xFF;
1361 else if (XCHARSET_DIMENSION (charset_by_leading_byte (i)) == 1) 1367 else if (LEADING_BYTE_CONTROL_1 == i)
1362 i = (((i - FIELD2_TO_OFFICIAL_LEADING_BYTE) << 7) 1368 i = ((reg[rrr] & 0xFF) - 0xA0);
1363 | (reg[rrr] & 0x7F)); 1369 else if (POSSIBLE_LEADING_BYTE_P(i) &&
1364 else if (i < MAX_LEADING_BYTE_OFFICIAL_2) 1370 !NILP(charset_by_leading_byte(i))
1365 i = ((i - FIELD1_TO_OFFICIAL_LEADING_BYTE) << 14) | reg[rrr]; 1371 {
1366 else 1372 if (XCHARSET_DIMENSION (charset_by_leading_byte (i)) == 1)
1367 i = ((i - FIELD1_TO_PRIVATE_LEADING_BYTE) << 14) | reg[rrr]; 1373 i = (((i - FIELD2_TO_OFFICIAL_LEADING_BYTE) << 7)
1374 | (reg[rrr] & 0x7F));
1375 else if (i < MAX_LEADING_BYTE_OFFICIAL_2)
1376 i = ((i - FIELD1_TO_OFFICIAL_LEADING_BYTE) << 14)
1377 | reg[rrr];
1378 else
1379 i = ((i - FIELD1_TO_PRIVATE_LEADING_BYTE) << 14) | reg[rrr];
1380 }
1381 else
1382 {
1383 /* No charset we know about; use U+3012 GETA MARK */
1384 i = make_ichar
1385 (charset_by_leading_byte(LEADING_BYTE_JAPANESE_JISX0208),
1386 34, 46);
1387 }
1368 1388
1369 CCL_WRITE_CHAR (i); 1389 CCL_WRITE_CHAR (i);
1370 1390
1371 break; 1391 break;
1372 1392
1421 break; 1441 break;
1422 } 1442 }
1423 1443
1424 for (;i < j;i++) 1444 for (;i < j;i++)
1425 { 1445 {
1426
1427 size = XVECTOR (Vcode_conversion_map_vector)->size; 1446 size = XVECTOR (Vcode_conversion_map_vector)->size;
1428 point = XINT (ccl_prog[ic++]); 1447 point = XINT (ccl_prog[ic++]);
1429 if (point >= size) continue; 1448 if (point >= size) continue;
1430 map = 1449 map =
1431 XVECTOR (Vcode_conversion_map_vector)->contents[point]; 1450 XVECTOR (Vcode_conversion_map_vector)->contents[point];