summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMike Pall <mike>2013-02-03 12:47:52 +0100
committerMike Pall <mike>2013-02-03 12:47:52 +0100
commit8b46013fdd7a7aad2f3da5cd9b35e0a17be34225 (patch)
tree94907392bcbfae3b3c8d66e574663e5e1c6f336d /src
parentfe9934feea0a8d580de19389f1a54d6cd4563d6b (diff)
downloadluajit-8b46013fdd7a7aad2f3da5cd9b35e0a17be34225.tar.gz
luajit-8b46013fdd7a7aad2f3da5cd9b35e0a17be34225.tar.bz2
luajit-8b46013fdd7a7aad2f3da5cd9b35e0a17be34225.zip
FFI: Stricter parsing of declaration specifiers.
Diffstat (limited to 'src')
-rw-r--r--src/lj_cparse.c53
1 files changed, 30 insertions, 23 deletions
diff --git a/src/lj_cparse.c b/src/lj_cparse.c
index 9121da11..7c037e2c 100644
--- a/src/lj_cparse.c
+++ b/src/lj_cparse.c
@@ -1469,43 +1469,50 @@ static CPscl cp_decl_spec(CPState *cp, CPDecl *decl, CPscl scl)
1469 1469
1470 for (;;) { /* Parse basic types. */ 1470 for (;;) { /* Parse basic types. */
1471 cp_decl_attributes(cp, decl); 1471 cp_decl_attributes(cp, decl);
1472 if (cp->tok >= CTOK_FIRSTDECL && cp->tok <= CTOK_LASTDECLFLAG) {
1473 uint32_t cbit;
1474 if (cp->ct->size) {
1475 if (sz) goto end_decl;
1476 sz = cp->ct->size;
1477 }
1478 cbit = (1u << (cp->tok - CTOK_FIRSTDECL));
1479 cds = cds | cbit | ((cbit & cds & CDF_LONG) << 1);
1480 if (cp->tok >= CTOK_FIRSTSCL) {
1481 if (!(scl & cbit)) cp_errmsg(cp, cp->tok, LJ_ERR_FFI_BADSCL);
1482 } else if (tdef) {
1483 goto end_decl;
1484 }
1485 cp_next(cp);
1486 continue;
1487 }
1488 if (sz || tdef ||
1489 (cds & (CDF_SHORT|CDF_LONG|CDF_SIGNED|CDF_UNSIGNED|CDF_COMPLEX)))
1490 break;
1472 switch (cp->tok) { 1491 switch (cp->tok) {
1473 case CTOK_STRUCT: 1492 case CTOK_STRUCT:
1474 tdef = cp_decl_struct(cp, decl, CTINFO(CT_STRUCT, 0)); 1493 tdef = cp_decl_struct(cp, decl, CTINFO(CT_STRUCT, 0));
1475 break; 1494 continue;
1476 case CTOK_UNION: 1495 case CTOK_UNION:
1477 tdef = cp_decl_struct(cp, decl, CTINFO(CT_STRUCT, CTF_UNION)); 1496 tdef = cp_decl_struct(cp, decl, CTINFO(CT_STRUCT, CTF_UNION));
1478 break; 1497 continue;
1479 case CTOK_ENUM: 1498 case CTOK_ENUM:
1480 tdef = cp_decl_enum(cp, decl); 1499 tdef = cp_decl_enum(cp, decl);
1481 break; 1500 continue;
1482 case CTOK_IDENT: 1501 case CTOK_IDENT:
1483 if (!ctype_istypedef(cp->ct->info) || sz || tdef || 1502 if (ctype_istypedef(cp->ct->info)) {
1484 (cds & (CDF_SHORT|CDF_LONG|CDF_SIGNED|CDF_UNSIGNED|CDF_COMPLEX))) 1503 tdef = ctype_cid(cp->ct->info); /* Get typedef. */
1485 goto end_decl; 1504 cp_next(cp);
1486 tdef = ctype_cid(cp->ct->info); /* Get typedef. */ 1505 continue;
1487 cp_next(cp); 1506 }
1488 break; 1507 break;
1489 case '$': 1508 case '$':
1490 tdef = cp->val.id; 1509 tdef = cp->val.id;
1491 cp_next(cp); 1510 cp_next(cp);
1492 break; 1511 continue;
1493 default: 1512 default:
1494 if (cp->tok >= CTOK_FIRSTDECL && cp->tok <= CTOK_LASTDECLFLAG) { 1513 break;
1495 uint32_t cbit;
1496 if (cp->ct->size) {
1497 if (sz) goto end_decl;
1498 sz = cp->ct->size;
1499 }
1500 cbit = (1u << (cp->tok - CTOK_FIRSTDECL));
1501 cds = cds | cbit | ((cbit & cds & CDF_LONG) << 1);
1502 if (cp->tok >= CTOK_FIRSTSCL && !(scl & cbit))
1503 cp_errmsg(cp, cp->tok, LJ_ERR_FFI_BADSCL);
1504 cp_next(cp);
1505 break;
1506 }
1507 goto end_decl;
1508 } 1514 }
1515 break;
1509 } 1516 }
1510end_decl: 1517end_decl:
1511 1518