0

I'm almost there on speller but I think I need another nudge before I can pass check50.

I had the same valgrind error that some others seemed to be getting (Conditional jump or move depends on uninitialised value(s)), and by looking through those posts was able to solve that issue.

After that, my valgrind seemed to be happy:

~/workspace/pset5/speller/ $ help50 valgrind --leak-check=full ./speller texts/ralph.txt ==4416== Memcheck, a memory error detector
==4416== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
==4416== Using Valgrind-3.10.1 and LibVEX; rerun with -h for copyright info
==4416== Command: ./speller texts/ralph.txt
==4416== 

MISSPELLED WORDS

Wiggum

WORDS MISSPELLED:     1
WORDS IN DICTIONARY:  143091
WORDS IN TEXT:        20
TIME IN load:         4.10
TIME IN check:        0.00
TIME IN size:         0.00
TIME IN unload:       1.98
TIME IN TOTAL:        6.09

==4416== 
==4416== HEAP SUMMARY:
==4416==     in use at exit: 0 bytes in 0 blocks
==4416==   total heap usage: 367,084 allocs, 367,084 frees, 82,227,504 bytes allocated
==4416== 
==4416== All heap blocks were freed -- no leaks are possible
==4416== 
==4416== For counts of detected and suppressed errors, rerun with: -v
==4416== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

Helping with...                                                                                                                                                                                     

==4416== All heap blocks were freed -- no leaks are possible
...
==4416== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

Looks like your program doesn't have any memory-related errors! Be sure, though, to test it with other inputs!

My austin powers output also matches the staff solution.

Now, running check50 passes all the tests except the last one:

~/workspace/pset5/speller/ $ check50 cs50/2017/x/speller
Connecting.....
Authenticating.....
Preparing........
Uploading.........
Checking.........
:) dictionary.c, dictionary.h, and Makefile exist
:) speller compiles
:) handles most basic words properly
:) handles min length (1-char) words
:) handles max length (45-char) words
:) handles words with apostrophes properly
:) spell-checking is case-insensitive
:( handles substrings properly
    valgrind tests failed; rerun with --log for more information.
See https://cs50.me/checks/ceadf0e4c44837b38ec997a7752f858c70e8b13c for more detail.    


{...after rerunning check50 with --log...}


:( handles substrings properly
    valgrind tests failed; rerun with --log for more information.
    running valgrind ./speller substring/dict substring/text...
    checking for output "MISSPELLED WORDS

ca
cats
caterpill
caterpillars

WORDS MISSPELLED: 4
WORDS IN DICTIONARY: 2
WORDS IN TEXT: 6
"...
    checking that program exited with status 0...
    checking for valgrind errors... 
        Conditional jump or move depends on uninitialised value(s): (file: speller.c, line: 100)

After looking through the other posts, I haven't found any about only failing the last step of check50, and I'm really confused why it would reference line 100 of speller.c, a file I haven't changed and a blank line in the code at that. I've tried running update50 and rechecking, and have taken a look at the code surrounding line 100 in speller.c, but I'm still at a loss for what could be wrong. Hopefully it's something I've overlooked and can be a simple fix.


Edit (solved): I feel very silly now, but in short the error came about because I "fixed" my previous error by initializing values of children pointers, but forgot to initialize the sentinel value of the node. I had assumed booleans always initialize to zero/false due to some previous experience in other languages. It was a valuable lesson to learn that this shouldn't be taken for granted in C, and especially not when using malloc. Explicitly initializing the sentinel value solved the issue.

Thanks to Blauelf for the tip to make my own local text file to use with dictionary/small for additional debugging; my lazy brain had ignored this as a possibility. Rerunning valgrind on the local files showed that the error stemmed from a line in speller.c where a boolean variable (misspelled) was being assigned to the return value of a function (check).

1

So dict they use is small containing

cat
caterpillar

and text is

ca cat cats caterpill caterpillar caterpillars

Maybe this helps in reproducing locally, unless they use their own speller.c (which could have anything at line 100), which they totally can, as you're supposed to make changes to dictionary.c only. This alternative version might include a better interface or additional output useful for automated testing.

I don't know what your speller.c looks like, my two versions (from different years) all have a very innocent-looking line 100, in the current download it's even an empty line, that's probably the version you have. So that line number is indeed not very helpful :-/

If you cannot find a mistake in your dictionary.c, maybe replace the other files with freshly downloaded versions? I just "transplanted" my old code into a freshly downloaded dictionary.c, and it works as well as before.

If you cannot reproduce the mistake, and have no idea what the reason might be, maybe post your code.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .