Changeset 72954 in vbox for trunk/src/VBox/Runtime/common/misc/json.cpp
- Timestamp:
- Jul 7, 2018 6:30:06 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/misc/json.cpp
r69520 r72954 530 530 int rc = VINF_SUCCESS; 531 531 size_t cchStr = 0; 532 char szTmp[_4K]; 533 RT_ZERO(szTmp); 532 size_t cchStrMax = _4K; 533 char *pszTmp = (char *)RTMemAllocZ(cchStrMax * sizeof(char)); 534 if (RT_UNLIKELY(!pszTmp)) 535 return VERR_NO_STR_MEMORY; 536 537 RT_BZERO(pszTmp, cchStrMax); 534 538 535 539 Assert(rtJsonTokenizerGetCh(pTokenizer) == '\"'); … … 542 546 while ( ch != '\"' 543 547 && ch != '\0' 544 && cchStr < sizeof(szTmp) - 1)548 && RT_SUCCESS(rc)) 545 549 { 546 550 if (ch == '\\') … … 552 556 { 553 557 case '\"': 554 szTmp[cchStr] = '\"';558 pszTmp[cchStr] = '\"'; 555 559 break; 556 560 case '\\': 557 szTmp[cchStr] = '\\';561 pszTmp[cchStr] = '\\'; 558 562 break; 559 563 case '/': 560 szTmp[cchStr] = '/';564 pszTmp[cchStr] = '/'; 561 565 break; 562 566 case '\b': 563 szTmp[cchStr] = '\b';567 pszTmp[cchStr] = '\b'; 564 568 break; 565 569 case '\n': 566 szTmp[cchStr] = '\n';570 pszTmp[cchStr] = '\n'; 567 571 break; 568 572 case '\f': 569 szTmp[cchStr] = '\f';573 pszTmp[cchStr] = '\f'; 570 574 break; 571 575 case '\r': 572 szTmp[cchStr] = '\r';576 pszTmp[cchStr] = '\r'; 573 577 break; 574 578 case '\t': 575 szTmp[cchStr] = '\t';579 pszTmp[cchStr] = '\t'; 576 580 break; 577 581 case 'u': … … 583 587 } 584 588 else 585 szTmp[cchStr] = ch; 589 pszTmp[cchStr] = ch; 590 591 if (RT_FAILURE(rc)) 592 break; 593 586 594 cchStr++; 587 595 rtJsonTokenizerSkipCh(pTokenizer); 596 if (cchStr == cchStrMax - 1) 597 { 598 /* Increase string space. */ 599 size_t cchStrMaxNew = cchStrMax + _4K; 600 char *pszTmpNew = (char *)RTMemRealloc(pszTmp, cchStrMaxNew * sizeof(char)); 601 if (RT_UNLIKELY(!pszTmpNew)) 602 { 603 rc = VERR_NO_STR_MEMORY; 604 break; 605 } 606 607 RT_BZERO(&pszTmpNew[cchStr], _4K); 608 pszTmp = pszTmpNew; 609 cchStrMax = cchStrMaxNew; 610 } 588 611 ch = rtJsonTokenizerGetCh(pTokenizer); 589 612 } 590 613 591 if (rtJsonTokenizerGetCh(pTokenizer) == '\"') 592 rtJsonTokenizerSkipCh(pTokenizer); /* Skip closing " */ 593 594 pToken->Class.String.pszStr = RTStrDupN(&szTmp[0], cchStr); 595 if (pToken->Class.String.pszStr) 596 pToken->Pos.iChEnd += cchStr; 597 else 598 rc = VERR_NO_STR_MEMORY; 614 if (RT_SUCCESS(rc)) 615 { 616 if (rtJsonTokenizerGetCh(pTokenizer) == '\"') 617 rtJsonTokenizerSkipCh(pTokenizer); /* Skip closing " */ 618 619 pToken->Class.String.pszStr = RTStrDupN(pszTmp, cchStr); 620 if (pToken->Class.String.pszStr) 621 pToken->Pos.iChEnd += cchStr; 622 else 623 rc = VERR_NO_STR_MEMORY; 624 } 625 626 if (pszTmp) 627 RTMemFree(pszTmp); 628 599 629 return rc; 600 630 } … … 943 973 cMembersMax += 10; 944 974 PRTJSONVALINT *papValuesNew = (PRTJSONVALINT *)RTMemRealloc(papValues, cMembersMax * sizeof(PRTJSONVALINT)); 945 char **papszNamesNew = (char **)RTMemRealloc(pap Values, cMembersMax * sizeof(char *));975 char **papszNamesNew = (char **)RTMemRealloc(papszNames, cMembersMax * sizeof(char *)); 946 976 if (RT_UNLIKELY(!papValuesNew || !papszNamesNew)) 947 977 {
Note:
See TracChangeset
for help on using the changeset viewer.