https://bugs.kde.org/show_bug.cgi?id=492389

Paul Floyd <[email protected]> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |NOT A BUG
             Status|REPORTED                    |RESOLVED

--- Comment #6 from Paul Floyd <[email protected]> ---
There is a bug in your code

diff --git a/hangman.c.orig b/hangman.c
index 5372acf..c3dc384 100644
--- a/hangman.c.orig
+++ b/hangman.c
@@ -177,6 +177,7 @@ struct game_instance new_game() {
     for (int i = 0; i < (strlen(word)); i++) {
         current_game.hidden[i] = '_';
     }
+    current_game.hidden[current_game.size] = '\0';
     current_game.incorrect = 0;
     current_game.guesses_size = 0;

>From what I see, if the user fails then you get no error. If the user succeeds
then there are no more '_' characters in 'hidden', so when this line

    while ((strchr(game.hidden, '_') != NULL) && game.incorrect <= 12) {

is executed the uninitialised termination byte gets read and Valgrind reports
an error.

I can't see any nondeterminism in Valgrind.

-- 
You are receiving this mail because:
You are watching all bug changes.

Reply via email to