home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l350 / 3.ddi / EXAMPLES / MSC / EXCEP.C < prev    next >
Encoding:
C/C++ Source or Header  |  1993-02-01  |  858 b   |  42 lines

  1. //
  2. // EXCEP.C -- Sample structured exception handler.
  3. //            Detects NULL pointers passed to strcpy().
  4. //            Link this program with -OFFSET 1000h so NULL pointer references
  5. //            will cause a page fault exception.
  6. //
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <string.h>
  10. #include <excpt.h>
  11.  
  12. char *SafeStrcpy(char *dstp, char *srcp);
  13.  
  14. int main()
  15. {
  16.     char    buf[256];
  17.  
  18.     if (SafeStrcpy(buf, "string1") == NULL)
  19.         printf("First call to SafeStrcpy failed!\n");
  20.     else 
  21.         printf("Buffer contains: %s\n", buf);
  22.  
  23.     if (SafeStrcpy(buf, NULL) == NULL)
  24.         printf("Second call to SafeStrcpy failed!\n");
  25.     else
  26.         printf("Buffer contains: %s\n", buf);
  27.  
  28.     return 0;
  29. }
  30.  
  31. char *SafeStrcpy(char *dstp, char *srcp)
  32. {
  33.     try
  34.     {
  35.         return strcpy(dstp, srcp);
  36.     }
  37.     except (EXCEPTION_EXECUTE_HANDLER)
  38.     {
  39.         return NULL;
  40.     }
  41. }
  42.