Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

94 lines
2.0 KiB

  1. /*
  2. * stddebug.c
  3. *
  4. * Debugging stubs for std encoder
  5. */
  6. #include <string.h>
  7. #include <stdio.h>
  8. #include <crtdbg.h>
  9. #include "deflate.h"
  10. #ifdef FULL_DEBUG
  11. // verify all hash chains
  12. void StdEncoderVerifyHashes(t_encoder_context *context, long bufpos)
  13. {
  14. int i;
  15. const t_search_node *lookup = context->std_encoder->lookup;
  16. const t_search_node *prev = context->std_encoder->prev;
  17. const BYTE *window = context->std_encoder->window;
  18. for (i = 0; i < STD_ENCODER_HASH_TABLE_SIZE; i++)
  19. {
  20. t_search_node where = lookup[i];
  21. t_search_node next_where;
  22. while (where != 0 && bufpos - where < WINDOW_SIZE)
  23. {
  24. int hash = STD_ENCODER_RECALCULATE_HASH(where);
  25. _ASSERT(hash == i);
  26. next_where = prev[where & WINDOW_MASK];
  27. if (bufpos - next_where >= WINDOW_SIZE)
  28. break;
  29. _ASSERT(next_where < where);
  30. where = next_where;
  31. }
  32. }
  33. }
  34. // verify that a particular hash chain is correct
  35. void StdEncoderVerifyHashChain(t_encoder_context *context, long bufpos, int chain_number)
  36. {
  37. const t_search_node *lookup = context->std_encoder->lookup;
  38. const t_search_node *prev = context->std_encoder->prev;
  39. BYTE *window = context->std_encoder->window;
  40. t_search_node where;
  41. t_search_node next_where;
  42. int print = 0;
  43. top:
  44. where = lookup[chain_number];
  45. // if (print)
  46. // printf("Verify chain %d\n", chain_number);
  47. while (where != 0 && bufpos - where < WINDOW_SIZE)
  48. {
  49. int hash = STD_ENCODER_RECALCULATE_HASH(where);
  50. BYTE *window = context->std_encoder->window;
  51. // if (print)
  52. // printf(" loc %d: char = %3d %3d %3d\n", where, window[where], window[where+1], window[where+2]);
  53. if (hash != chain_number && print == 0)
  54. {
  55. print = 1;
  56. goto top;
  57. }
  58. _ASSERT(hash == chain_number);
  59. next_where = prev[where & WINDOW_MASK];
  60. if (bufpos - next_where >= WINDOW_SIZE)
  61. break;
  62. if (next_where >= where && print == 0)
  63. {
  64. print = 1;
  65. goto top;
  66. }
  67. _ASSERT(next_where < where);
  68. where = next_where;
  69. }
  70. }
  71. #endif