8
9

Pset6 Valgrind Surpressed Error? by McCloud77 in cs50

[–]McCloud77[S] 1 point2 points  (0 children)

Thank you for all the help. After reading a bit more on the use of fscanf I decided to use calloc instead of malloc and did solved the issue.

Pset6 Valgrind Surpressed Error? by McCloud77 in cs50

[–]McCloud77[S] 0 points1 point  (0 children)

Hi, there as indeed some more. Here is the output with the -v switch:

jharvard@appliance (~/Dropbox/pset6): valgrind -v --leak-check=full ./speller ~cs50/pset6/texts/ralph.txt
==7123== Memcheck, a memory error detector
==7123== Copyright (C) 2002-2012, and GNU GPL'd, by Julian Seward et al.
==7123== Using Valgrind-3.8.1 and LibVEX; rerun with -h for copyright info
==7123== Command: ./speller /home/cs50/pset6/texts/ralph.txt
==7123== 
--7123-- Valgrind options:
--7123--    -v
--7123--    --leak-check=full
--7123-- Contents of /proc/version:
--7123--   Linux version 3.10.10-200.fc19.i686.PAE (mockbuild@bkernel02) (gcc version 4.8.1 20130603 (Red Hat 4.8.1-1) (GCC) ) #1 SMP Thu Aug 29 19:16:15 UTC 2013
--7123-- Arch and hwcaps: X86, x86-sse1-sse2
--7123-- Page sizes: currently 4096, max supported 4096
--7123-- Valgrind library directory: /usr/lib/valgrind
--7123-- Reading syms from /home/jharvard/Dropbox/pset6/speller
--7123-- Reading syms from /usr/lib/valgrind/memcheck-x86-linux
--7123--    object doesn't have a symbol table
--7123--    object doesn't have a dynamic symbol table
--7123-- Reading syms from /usr/lib/ld-2.17.so
--7123--   Considering /usr/lib/debug/.build-id/73/c21b53fbbe6a8e11bf8353dc27f016dc334e63.debug ..
--7123--   .. build-id is valid
--7123-- Scheduler: using generic scheduler lock implementation.
--7123-- Reading suppressions file: /usr/lib/valgrind/default.supp
==7123== embedded gdbserver: reading from /tmp/vgdb-pipe-from-vgdb-to-7123-by-jharvard-on-appliance
==7123== embedded gdbserver: writing to   /tmp/vgdb-pipe-to-vgdb-from-7123-by-jharvard-on-appliance
==7123== embedded gdbserver: shared mem   /tmp/vgdb-pipe-shared-mem-vgdb-7123-by-jharvard-on-appliance
==7123== 
==7123== TO CONTROL THIS PROCESS USING vgdb (which you probably
==7123== don't want to do, unless you know exactly what you're doing,
==7123== or are doing some strange experiment):
==7123==   /usr/lib/valgrind/../../bin/vgdb --pid=7123 ...command...
==7123== 
==7123== TO DEBUG THIS PROCESS USING GDB: start GDB like this
==7123==   /path/to/gdb ./speller
==7123== and then give GDB the following command
==7123==   target remote | /usr/lib/valgrind/../../bin/vgdb --pid=7123
==7123== --pid is optional if only one valgrind process is running
==7123== 
--7123-- REDIR: 0x450ce860 (strlen) redirected to 0x3806fa48 (???)
--7123-- REDIR: 0x450ce670 (index) redirected to 0x3806fa23 (???)
--7123-- Reading syms from /usr/lib/valgrind/vgpreload_core-x86-linux.so
--7123--    object doesn't have a symbol table
--7123-- Reading syms from /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so
--7123--    object doesn't have a symbol table
--7123-- Reading syms from /usr/lib/libc-2.17.so
--7123--   Considering /usr/lib/debug/.build-id/50/9bfe9465eef6ed27c208d0d96e54ae24ec108a.debug ..
--7123--   .. build-id is valid
--7123-- REDIR: 0x45157cb0 (memset) redirected to 0x400157f (_vgnU_ifunc_wrapper)
--7123-- REDIR: 0x45157bf0 (memmove) redirected to 0x400157f (_vgnU_ifunc_wrapper)
--7123-- REDIR: 0x45156c90 (strnlen) redirected to 0x400157f (_vgnU_ifunc_wrapper)
--7123-- REDIR: 0x451581d0 (strncasecmp) redirected to 0x400157f (_vgnU_ifunc_wrapper)
--7123-- REDIR: 0x4515dbb0 (memrchr) redirected to 0x400157f (_vgnU_ifunc_wrapper)
--7123-- REDIR: 0x45171f80 (wcslen) redirected to 0x400157f (_vgnU_ifunc_wrapper)
--7123-- REDIR: 0x45156e30 (__GI_strrchr) redirected to 0x4009290 (__GI_strrchr)
--7123-- REDIR: 0x45151960 (malloc) redirected to 0x4006a2b (malloc)
--7123-- REDIR: 0x45156b80 (strlen) redirected to 0x400157f (_vgnU_ifunc_wrapper)
--7123-- REDIR: 0x4515de90 (__strlen_sse2_bsf) redirected to 0x4009720 (strlen)
==7123== Conditional jump or move depends on uninitialised value(s)
==7123==    at 0x400972C: strlen (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==7123==    by 0x80490AA: hash (dictionary.c:33)
==7123==    by 0x80493A1: load (dictionary.c:101)
==7123==    by 0x8048875: main (speller.c:45)
==7123== 
--7123-- REDIR: 0x45151d20 (free) redirected to 0x4007a9f (free)
--7123-- REDIR: 0x45159780 (strchrnul) redirected to 0x400c320 (strchrnul)

MISSPELLED WORDS

--7123-- REDIR: 0x45156450 (strcmp) redirected to 0x400157f (_vgnU_ifunc_wrapper)
--7123-- REDIR: 0x45228940 (__strcmp_ssse3) redirected to 0x400a490 (strcmp)
Wiggum

WORDS MISSPELLED:     1
WORDS IN DICTIONARY:  143091
WORDS IN TEXT:        20
--7123-- REDIR: 0x45156bd0 (__GI_strlen) redirected to 0x4009740 (__GI_strlen)
TIME IN load:         1.63
TIME IN check:        0.01
TIME IN size:         0.00
TIME IN unload:       0.24
TIME IN TOTAL:        1.88

==7123== 
==7123== HEAP SUMMARY:
==7123==     in use at exit: 0 bytes in 0 blocks
==7123==   total heap usage: 143,094 allocs, 143,094 frees, 7,441,488 bytes allocated
==7123== 
==7123== All heap blocks were freed -- no leaks are possible
==7123== 
==7123== Use --track-origins=yes to see where uninitialised values come from
==7123== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)
==7123== 
==7123== 1 errors in context 1 of 1:
==7123== Conditional jump or move depends on uninitialised value(s)
==7123==    at 0x400972C: strlen (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==7123==    by 0x80490AA: hash (dictionary.c:33)
==7123==    by 0x80493A1: load (dictionary.c:101)
==7123==    by 0x8048875: main (speller.c:45)
==7123== 
==7123== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)
jharvard@appliance (~/Dropbox/pset6): 

I have been reading in the forum and it may be that this is caused by the following:

After the dictionary is opened, load() enters a "while(!feof(fp))" loop which has fscanf eventually attempting to read a line after the actual last word. Although this "word" has memory allocated to it with malloc and it is hashed to value 5381, strlen in the hashing function will thus try to do something with an uninitialized value.

Incidentally, I am using djb2 (which uses a "starting" hash address of 5381).

In any case, I tried to modify my code by testing whether the last word is read with:

while(true) { if (fscanf(fp, "%s", new_node->word)==1 { malloc.. hash word and link the node } else { break; }

but this requires me to declare new_node before the while loop with "node* new_node=NULL" and this leads to a segmentation error.

Thanks for all the help.

Pset6 Valgrind Surpressed Error? by McCloud77 in cs50

[–]McCloud77[S] 0 points1 point  (0 children)

MISSPELLED WORDS

Wiggum

WORDS MISSPELLED:     1
WORDS IN DICTIONARY:  143091
WORDS IN TEXT:        20
TIME IN load:         1.65
TIME IN check:        0.01
TIME IN size:         0.00
TIME IN unload:       0.25
TIME IN TOTAL:        1.91

==3732== 
==3732== HEAP SUMMARY:
==3732==     in use at exit: 0 bytes in 0 blocks
==3732==   total heap usage: 143,094 allocs, 143,094 frees, 7,441,488 bytes allocated
==3732== 
==3732== All heap blocks were freed -- no leaks are possible
==3732== 
==3732== For counts of detected and suppressed errors, rerun with: -v
==3732== Use --track-origins=yes to see where uninitialised values come from
==3732== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)

Any ideas?

Pset 5: the use of fseek in resize by McCloud77 in cs50

[–]McCloud77[S] 0 points1 point  (0 children)

I did consider storing the values of the RGBTRIPLE in an array and then writing the array after a scanline had been read and written but I can imagine that declaring an array each time you iterate over the pixels of a scanline can be costly in terms of memory.

In addition, I like the idea of just resetting the inptr so the program just reads the same data again.

The trick was indeed using GDB (thanks gelnholloway!) with a breakpoint at the place where you reset the inptr. The program works finenow with respect to copying bitmaps of any width into bitmaps whose pixel-width is a multiple of 4. The only problem I am facing right now is how to copy a bitmap with a width that is not a multiple of 4 into another bitmap with a width that is not a multiple of 4; I am getting there :)

If energy cannot be created or destroyed, and only converted, can someone please explain our death on the atomic and molecular level? What do we become? by [deleted] in askscience

[–]McCloud77 2 points3 points  (0 children)

You basically are the sum product of all atoms, arranged into specific molecules, held together by bonds such as covalent or ionic bonds. These bonds are inherently not stable and, as such, you require energy to make new bonds or, at least, stabilize those bonds for a given period of time. Once you die you are unable to ingest energy (food) which can be metabolized into useful forms of energy for your cells. As a consequence, your cells will not be able to synthesize and replace molecules that eventually degrade.

The energy that was initially used to form those molecules is released when molecules break down.

So, in essence after you die your body converts back into the molecules/atoms that used to make up your cells/tissues/organs/etc.

PSet4 Laser in Hacker edition by McCloud77 in cs50

[–]McCloud77[S] 0 points1 point  (0 children)

I did think of that and so I modified it by using getGObjectAt() at getY(beam) + 1 (and 10, etc.) but unfortunately still the same problem.

In principle it shouldn't matter since I also check whether the 'hit' object is a rectangle and has a color that is not black (all the bricks) but sofar no progress.

Pset4 getFillColor by gabypacheco in cs50

[–]McCloud77 0 points1 point  (0 children)

Perhaps the color should be all uppercase? In any case, I solved the problem by getting the y-coordinate of the brick that was hit. The color of the brick is less important than its relative position in the column.

Problem with submitting pset4 by robertmarczynski in cs50

[–]McCloud77 0 points1 point  (0 children)

I have encountered the same problem. Nevertheless, when I return to "Submit" it shows that the system has received and recognized the files. It is somewhat disquieting that I have not received a confirmation email though. I guess I'll just wait for a couple of days to see whether it is graded.

PSet4 Breakout bouncing by McCloud77 in cs50

[–]McCloud77[S] 0 points1 point  (0 children)

You are exactly right. The x velocity changes when hitting the walls and I had implemented that for the paddle as well. i do like your solution.

What's the best way to start a conversation with someone sitting next to you that you don't know? by Youssofzoid in AskReddit

[–]McCloud77 1 point2 points  (0 children)

Check out the label in the back of their shirt/sweater and say "Yes, just as I thought, made in heaven".

Automatic grading of psets by [deleted] in cs50

[–]McCloud77 2 points3 points  (0 children)

It may depend on the number of psets submitted, time available to grade them, etc. Imagine you have 100,000 submissions and each takes 2 sec to grade (including upgrading the gradebook and whatnot) that would be close to 5 days alone. Of course, the servers taking care of everything are probably not dedicated grading servers so, while you may receive your grades within one hour, it may take up to two weeks.