Search code examples
cvalgrind

Valgrind -> Conditional jump or move depends on uninitialised value(s)


I do not understand why I'm going to sort this error "Conditional jump or move depends on uninitialised value(s)", while all variables are initialized, including defines them.

#include "shell.h"

int     ft_complete_apply_key(t_cmd *cmd)
{
    int     key;

    key = cmd->last_key;
    if (key == KEY_TERM_RIGHT || key == KEY_TERM_LEFT
        || key == KEY_TERM_HOME || key == KEY_TERM_END) // error here
        return (ft_move_cursor(cmd));
    if (key == KEY_TERM_DEL)
        return (ft_complete_apply_del(cmd));
    if (key == KEY_TERM_ENTER)
        return (ft_complete_apply_enter(cmd));
    return (ft_complete_apply_printable(cmd));
}

Solution

  • int ft_interactive_read_key(void)
    {
        int     nread;
        char    seq[4];
    
        while ((nread = read(STDIN_FILENO, &seq[0], 1)) != 1)
        {
            if (nread == -1)
                return (0);
        }
        if (seq[0] == '\x1b')
        {
            if (read(STDIN_FILENO, &seq[1], 1) != 1)
                return (ft_atoi(seq));
            if (read(STDIN_FILENO, &seq[2], 1) != 1)
                return (ft_atoi(seq));
            return (*(int*)seq);
        }
        else
        {
            return (seq[0]);
        }
    }
    

    I am told that the error can come from this function apparently. I do not see how it is possible. The result of this function goes in cmd->last_key = ft_interative_read_key();

    EDIT:

    Actually it comes from the seq array that was not initialized.