Method for protecting an electronic device executing a program against fault injection and type confusion attacks likely to affect a variable intended to be used by the program, the method being characterized in that it comprises steps of: • calculating integrity check data (X, Y) of variable, wherein the integrity check data depend on: ∘ a type of the variable, and ∘ a value of the variable stored in an execution stack and/or a first addressing datum stored in a first index register, wherein the first addressing datum is adapted to locate the value stored in the execution stack, • storing the integrity check data (X, Y) on the variable in at least one control stack (P2, P3) different to the execution stack, • storing, in a second index register, a unique second addressing datum adapted to locate the integrity check data (X, Y) in the or each control stack (P2, P3). • verification of integrity of the variable performed when a program commands reading of the addressing datum of the variable and/or reading of the value of the variable, said verification comprising comparison between the integrity check data stored in the or each control stack (P2, P3) and new integrity check data calculated on the basis of: ∘ a type (T, T') of the variable seen by the program during the reading command, and ∘ the value (V, V') of the variable present in the execution stack and/or of the addressing datum (A, A') present in the first index register during the reading command. • calculating integrity check data (X, Y) of variable, wherein the integrity check data depend on: ∘ a type of the variable, and ∘ a value of the variable stored in an execution stack and/or a first addressing datum stored in a first index register, wherein the first addressing datum is adapted to locate the value stored in the execution stack, ∘ a type of the variable, and ∘ a value of the variable stored in an execution stack and/or a first addressing datum stored in a first index register, wherein the first addressing datum is adapted to locate the value stored in the execution stack, • storing the integrity check data (X, Y) on the variable in at least one control stack (P2, P3) different to the execution stack, • storing, in a second index register, a unique second addressing datum adapted to locate the integrity check data (X, Y) in the or each control stack (P2, P3). • verification of integrity of the variable performed when a program commands reading of the addressing datum of the variable and/or reading of the value of the variable, said verification comprising comparison between the integrity check data stored in the or each control stack (P2, P3) and new integrity check data calculated on the basis of: ∘ a type (T, T') of the variable seen by the program during the reading command, and ∘ the value (V, V') of the variable present in the execution stack and/or of the addressing datum (A, A') present in the first index register during the reading command. ∘ a type (T, T') of the variable seen by the program during the reading command, and ∘ the value (V, V') of the variable present in the execution stack and/or of the addressing datum (A, A') present in the first index register during the reading command.