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.

92 lines
2.4 KiB

  1. //*********************************************************************
  2. //* Microsoft Windows **
  3. //* Copyright(c) Microsoft Corp., 1995 **
  4. //*********************************************************************
  5. //
  6. // CLIST.CPP
  7. //
  8. // HISTORY:
  9. //
  10. // 9/10/95 philco Created.
  11. // 4/05/96 VatsanP Copied from MSHTML to URLMON\DOWNLOAD
  12. // to use for the code downloader
  13. // changed name to CLIST.CXX to make JoahnnP happy :)
  14. //
  15. //
  16. // Templated list class "borrowed" from MFC 3.0. Used to manage a
  17. // list of IOleObject pointers to embedded items.
  18. //
  19. #include <cdlpch.h>
  20. #ifndef unix
  21. #include "..\inc\clist.hxx"
  22. #else
  23. #include "../inc/clist.hxx"
  24. #endif /* unix */
  25. BOOL AFXAPI AfxIsValidAddress(const void* lp, UINT nBytes, BOOL bReadWrite)
  26. {
  27. DEBUG_ENTER((DBG_DOWNLOAD,
  28. Bool,
  29. "AfxIsValidAddress",
  30. "%#x, %x, %B",
  31. lp, nBytes, bReadWrite
  32. ));
  33. // simple version using Win-32 APIs for pointer validation.
  34. BOOL bRet = (lp != NULL && !IsBadReadPtr(lp, nBytes) &&
  35. (!bReadWrite || !IsBadWritePtr((LPVOID)lp, nBytes)));
  36. DEBUG_LEAVE(bRet);
  37. return bRet;
  38. }
  39. CPlex* PASCAL CPlex::Create(CPlex*& pHead, UINT nMax, UINT cbElement)
  40. {
  41. DEBUG_ENTER((DBG_DOWNLOAD,
  42. Pointer,
  43. "CPlex::Create",
  44. "%#x, %x, %x",
  45. &pHead, nMax, cbElement
  46. ));
  47. ASSERT(nMax > 0 && cbElement > 0);
  48. CPlex* p = (CPlex*) new (BYTE[sizeof(CPlex) + nMax* cbElement]);
  49. // may throw exception
  50. Assert(p != NULL);
  51. p->nMax = nMax;
  52. p->nCur = 0;
  53. p->pNext = pHead;
  54. pHead = p; // change head (adds in reverse order for simplicity)
  55. DEBUG_LEAVE(p);
  56. return p;
  57. }
  58. void CPlex::FreeDataChain() // free this one and links
  59. {
  60. DEBUG_ENTER((DBG_DOWNLOAD,
  61. None,
  62. "CPlex::FreeDataChain",
  63. "this=%#x",
  64. this
  65. ));
  66. CPlex* p = this;
  67. while (p != NULL)
  68. {
  69. BYTE* bytes = (BYTE*) p;
  70. CPlex* pNext = p->pNext;
  71. delete (bytes);
  72. p = pNext;
  73. }
  74. DEBUG_LEAVE(0);
  75. }