fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. // A function to display an error message and then exit
  6. void fatal(char *message) {
  7. char error_message[100];
  8.  
  9. strcpy(error_message, "[!!] Fatal Error ");
  10. strncat(error_message, message, 83);
  11. perror(error_message);
  12. exit(-1);
  13. }
  14.  
  15. // An error checked malloc() wrapper function
  16. void *ec_malloc(unsigned int size) {
  17. void *ptr;
  18. ptr = malloc(size);
  19. if(ptr == NULL)
  20. fatal("in ec_malloc() on memory allocation");
  21. return ptr;
  22. }
  23.  
  24. // dumps raw memory in hex byte and printable split format
  25. void dump(const unsigned char *data_buffer, const unsigned int length) {
  26. unsigned char byte;
  27. unsigned int i, j;
  28. for(i=0; i < length; i++) {
  29. byte = data_buffer[i];
  30. printf("%02x ", data_buffer[i]); // display byte in hex
  31. if(((i%16)==15) || (i==length-1)) {
  32. for(j=0; j < 15-(i%16); j++)
  33. printf(" ");
  34. printf("| ");
  35. for(j=(i-(i%16)); j <= i; j++) { // display printable bytes from line
  36. byte = data_buffer[j];
  37. if((byte > 31) && (byte < 127)) // outside printable char range
  38. printf("%c", byte);
  39. else
  40. printf(".");
  41. }
  42. printf("\n"); // end of the dump line (each line 16 bytes)
  43. } // end if
  44. } // end for
  45. }
  46.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function 'void* ec_malloc(unsigned int)':
prog.cpp:20:50: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
       fatal("in ec_malloc() on memory allocation");
                                                  ^
/usr/lib/gcc/i586-linux-gnu/5/../../../i386-linux-gnu/crt1.o: In function `_start':
(.text+0x18): undefined reference to `main'
collect2: error: ld returned 1 exit status
stdout
Standard output is empty