| 515 | } |
| 516 | |
| 517 | ULONG Difference::apply(ULONG diffLength, ULONG outLength, UCHAR* const output) |
| 518 | { |
| 519 | /************************************** |
| 520 | * |
| 521 | * Apply a differences (delta) to a record. |
| 522 | * Return the length. |
| 523 | * |
| 524 | **************************************/ |
| 525 | if (diffLength > MAX_DIFFERENCES) |
| 526 | BUGCHECK(176); // msg 176 bad difference record |
| 527 | |
| 528 | auto differences = m_differences; |
| 529 | const auto end = differences + diffLength; |
| 530 | auto p = output; |
| 531 | const auto p_end = output + outLength; |
| 532 | |
| 533 | while (differences < end && p < p_end) |
| 534 | { |
| 535 | const int l = (signed char) *differences++; |
| 536 | |
| 537 | if (l > 0) |
| 538 | { |
| 539 | if (p + l > p_end) |
| 540 | BUGCHECK(177); // msg 177 applied differences will not fit in record |
| 541 | |
| 542 | if (differences + l > end) |
| 543 | BUGCHECK(176); // msg 176 bad difference record |
| 544 | |
| 545 | memcpy(p, differences, l); |
| 546 | p += l; |
| 547 | differences += l; |
| 548 | } |
| 549 | else |
| 550 | { |
| 551 | p += -l; |
| 552 | } |
| 553 | } |
| 554 | |
| 555 | while (differences < end) |
| 556 | { |
| 557 | if (*differences++) |
| 558 | BUGCHECK(177); // msg 177 applied differences will not fit in record |
| 559 | } |
| 560 | |
| 561 | const auto length = p - output; |
| 562 | |
| 563 | if (length > outLength) |
| 564 | BUGCHECK(177); // msg 177 applied differences will not fit in record |
| 565 | |
| 566 | return length; |
| 567 | } |
| 568 | |
| 569 | ULONG Difference::makeNoDiff(ULONG length) |
| 570 | { |
no outgoing calls
no test coverage detected