| 1498 | |
| 1499 | template<class SI_CHAR, class SI_STRLESS, class SI_CONVERTER> |
| 1500 | SI_Error |
| 1501 | CSimpleIniTempl<SI_CHAR,SI_STRLESS,SI_CONVERTER>::LoadData( |
| 1502 | const char * a_pData, |
| 1503 | size_t a_uDataLen |
| 1504 | ) |
| 1505 | { |
| 1506 | if (!a_pData) { |
| 1507 | return SI_OK; |
| 1508 | } |
| 1509 | |
| 1510 | // if the UTF-8 BOM exists, consume it and set mode to unicode, if we have |
| 1511 | // already loaded data and try to change mode half-way through then this will |
| 1512 | // be ignored and we will assert in debug versions |
| 1513 | if (a_uDataLen >= 3 && memcmp(a_pData, SI_UTF8_SIGNATURE, 3) == 0) { |
| 1514 | a_pData += 3; |
| 1515 | a_uDataLen -= 3; |
| 1516 | SI_ASSERT(m_bStoreIsUtf8 || !m_pData); // we don't expect mixed mode data |
| 1517 | SetUnicode(); |
| 1518 | } |
| 1519 | |
| 1520 | if (a_uDataLen == 0) { |
| 1521 | return SI_OK; |
| 1522 | } |
| 1523 | |
| 1524 | // determine the length of the converted data |
| 1525 | SI_CONVERTER converter(m_bStoreIsUtf8); |
| 1526 | size_t uLen = converter.SizeFromStore(a_pData, a_uDataLen); |
| 1527 | if (uLen == (size_t)(-1)) { |
| 1528 | return SI_FAIL; |
| 1529 | } |
| 1530 | |
| 1531 | // check converted data size is within supported limits (SI_MAX_FILE_SIZE) |
| 1532 | if (uLen >= (SI_MAX_FILE_SIZE / sizeof(SI_CHAR))) { |
| 1533 | return SI_FILE; |
| 1534 | } |
| 1535 | |
| 1536 | // allocate memory for the data, ensure that there is a NULL |
| 1537 | // terminator wherever the converted data ends |
| 1538 | SI_CHAR * pData = new(std::nothrow) SI_CHAR[uLen + 1]; |
| 1539 | if (!pData) { |
| 1540 | return SI_NOMEM; |
| 1541 | } |
| 1542 | memset(pData, 0, sizeof(SI_CHAR) * (uLen + 1)); |
| 1543 | |
| 1544 | // convert the data |
| 1545 | if (!converter.ConvertFromStore(a_pData, a_uDataLen, pData, uLen)) { |
| 1546 | delete[] pData; |
| 1547 | return SI_FAIL; |
| 1548 | } |
| 1549 | |
| 1550 | // parse it |
| 1551 | const static SI_CHAR empty = 0; |
| 1552 | SI_CHAR * pWork = pData; |
| 1553 | const SI_CHAR * pSection = ∅ |
| 1554 | const SI_CHAR * pItem = NULL; |
| 1555 | const SI_CHAR * pVal = NULL; |
| 1556 | const SI_CHAR * pComment = NULL; |
| 1557 |
nothing calls this directly
no test coverage detected