Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.72 KB | None | 0 0
  1. #include "bmp.h"
  2.  
  3. void extractMessage(BMPfile bmpfile)
  4. {
  5. void extractMessage(BMPfile bmpfile)
  6. {
  7. short index = 0;
  8. char word[16];
  9. unsigned char letter = 0;
  10. unsigned char count = 0;
  11. unsigned char temp;
  12. int width = getWidth(bmpfile);
  13. int height = getHeight(bmpfile);
  14. printf("The image has %d x %d pixelsn", width, height);
  15. for (int y = 0 ; y < height ; y++)
  16. {
  17. for (int x = 0 ; x < width ; x++)
  18. {
  19. pixel p = getPixel(bmpfile, x, y); /* read pixel */
  20. temp = p.green & 0x01;
  21. letter = letter << 1;
  22. letter = letter + temp;
  23. count += 1;
  24. if(count == 8){
  25. word[index] = letter;
  26. index += 1;
  27. count = 0;}
  28. if (letter == '0')
  29. {
  30. break;
  31. }
  32. }
  33. }
  34. for (int x=0; x < 16; x++)
  35. {
  36. printf("%c",word[x]);
  37. }
  38. }
  39.  
  40. Memcheck, a memory error detector
  41. ==13094== Copyright (C) 2002-2010, and GNU GPL'd, by Julian Seward et al.
  42. ==13094== Using Valgrind-3.6.0 and LibVEX; rerun with -h for copyright info
  43. ==13094== Command: ./p1 picture.bmp
  44. ==13094==
  45. The image has 450 x 683 pixels
  46. ==13094== Invalid write of size 1
  47. ==13094== at 0x400845: extractMessage (in /home/hauger3/hauger3/cs398/Lab2/p1)
  48. ==13094== by 0x400C72: main (in /home/hauger3/hauger3/cs398/Lab2/p1)
  49. ==13094== Address 0x7ff001000 is not stack'd, malloc'd or (recently) free'd
  50. ==13094==
  51. ==13094==
  52. ==13094== Process terminating with default action of signal 11 (SIGSEGV)
  53. ==13094== Access not within mapped region at address 0x7FF001000
  54. ==13094== at 0x400845: extractMessage (in /home/hauger3/hauger3/cs398/Lab2/p1)
  55. ==13094== by 0x400C72: main (in /home/hauger3/hauger3/cs398/Lab2/p1)
  56. ==13094== If you believe this happened as a result of a stack
  57. ==13094== overflow in your program's main thread (unlikely but
  58. ==13094== possible), you can try to increase the size of the
  59. ==13094== main thread stack using the --main-stacksize= flag.
  60. ==13094== The main thread stack size used in this run was 10485760.
  61. ==13094==
  62. ==13094== HEAP SUMMARY:
  63. ==13094== in use at exit: 568 bytes in 1 blocks
  64. ==13094== total heap usage: 1 allocs, 0 frees, 568 bytes allocated
  65. ==13094==
  66. ==13094== LEAK SUMMARY:
  67. ==13094== definitely lost: 0 bytes in 0 blocks
  68. ==13094== indirectly lost: 0 bytes in 0 blocks
  69. ==13094== possibly lost: 0 bytes in 0 blocks
  70. ==13094== still reachable: 568 bytes in 1 blocks
  71. ==13094== suppressed: 0 bytes in 0 blocks
  72. ==13094== Rerun with --leak-check=full to see details of leaked memory
  73. ==13094==
  74. ==13094== For counts of detected and suppressed errors, rerun with: -v
  75. ==13094== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 6 from 6)
  76. Segmentation fault
  77. [hauger3@linux6 Lab2]$ valgrind --leak-check=full ./p1 picture.bmp
  78. ==19793== Memcheck, a memory error detector
  79. ==19793== Copyright (C) 2002-2010, and GNU GPL'd, by Julian Seward et al.
  80. ==19793== Using Valgrind-3.6.0 and LibVEX; rerun with -h for copyright info
  81. ==19793== Command: ./p1 picture.bmp
  82. ==19793==
  83. The image has 450 x 683 pixels
  84. ==19793== Invalid write of size 1
  85. ==19793== at 0x400845: extractMessage (in /home/hauger3/hauger3/cs398/Lab2/p1)
  86. ==19793== by 0x400C72: main (in /home/hauger3/hauger3/cs398/Lab2/p1)
  87. ==19793== Address 0x7ff001000 is not stack'd, malloc'd or (recently) free'd
  88. ==19793==
  89. ==19793==
  90. ==19793== Process terminating with default action of signal 11 (SIGSEGV)
  91. ==19793== Access not within mapped region at address 0x7FF001000
  92. ==19793== at 0x400845: extractMessage (in /home/hauger3/hauger3/cs398/Lab2/p1)
  93. ==19793== by 0x400C72: main (in /home/hauger3/hauger3/cs398/Lab2/p1)
  94. ==19793== If you believe this happened as a result of a stack
  95. ==19793== overflow in your program's main thread (unlikely but
  96. ==19793== possible), you can try to increase the size of the
  97. ==19793== main thread stack using the --main-stacksize= flag.
  98. ==19793== The main thread stack size used in this run was 10485760.
  99. ==19793==
  100. ==19793== HEAP SUMMARY:
  101. ==19793== in use at exit: 568 bytes in 1 blocks
  102. ==19793== total heap usage: 1 allocs, 0 frees, 568 bytes allocated
  103. ==19793==
  104. ==19793== LEAK SUMMARY:
  105. ==19793== definitely lost: 0 bytes in 0 blocks
  106. ==19793== indirectly lost: 0 bytes in 0 blocks
  107. ==19793== possibly lost: 0 bytes in 0 blocks
  108. ==19793== still reachable: 568 bytes in 1 blocks
  109. ==19793== suppressed: 0 bytes in 0 blocks
  110. ==19793== Reachable blocks (those to which a pointer was found) are not shown.
  111. ==19793== To see them, rerun with: --leak-check=full --show-reachable=yes
  112. ==19793==
  113. ==19793== For counts of detected and suppressed errors, rerun with: -v
  114. ==19793== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 6 from 6)
  115. Segmentation fault
  116.  
  117. if(count == 8){
  118. word[index] = letter;
  119. index += 1;
  120. count = 0;
  121. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement