Method for protecting an electronic device executing a program against fault injection and type confusion attacks likely to affect a variable (Z) 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 (Z), wherein the integrity check data depend on: ∘ a type (T) of the variable (Z), and ∘ a value (V) of the variable (Z) stored in an execution stack (P1) and/or a first addressing datum (A) stored in a first index register (ind1), wherein the first addressing datum (A) is adapted to locate the value (V) stored in the execution stack (P1), • storing the integrity check data (X, Y) on the variable (Z) in at least one control stack (P2, P3) different to the execution stack (P1), • storing, in a second index register (ind2), a unique second addressing datum (A2) adapted to locate the integrity check data (X, Y) in the or each control stack (P2, P3). • verification of integrity of the variable (Z) performed when a program commands reading of the addressing datum (A) of the variable (Z) and/or reading of the value (V) of the variable (Z), 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 (Z) seen by the program during the reading command, and ∘ the value (V, V') of the variable (Z) present in the execution stack (P1) and/or of the addressing datum (A, A') present in the first index register (ind1) during the reading command. • calculating integrity check data (X, Y) of variable (Z), wherein the integrity check data depend on: ∘ a type (T) of the variable (Z), and ∘ a value (V) of the variable (Z) stored in an execution stack (P1) and/or a first addressing datum (A) stored in a first index register (ind1), wherein the first addressing datum (A) is adapted to locate the value (V) stored in the execution stack (P1), ∘ a type (T) of the variable (Z), and ∘ a value (V) of the variable (Z) stored in an execution stack (P1) and/or a first addressing datum (A) stored in a first index register (ind1), wherein the first addressing datum (A) is adapted to locate the value (V) stored in the execution stack (P1), • storing the integrity check data (X, Y) on the variable (Z) in at least one control stack (P2, P3) different to the execution stack (P1), • storing, in a second index register (ind2), a unique second addressing datum (A2) adapted to locate the integrity check data (X, Y) in the or each control stack (P2, P3). • verification of integrity of the variable (Z) performed when a program commands reading of the addressing datum (A) of the variable (Z) and/or reading of the value (V) of the variable (Z), 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 (Z) seen by the program during the reading command, and ∘ the value (V, V') of the variable (Z) present in the execution stack (P1) and/or of the addressing datum (A, A') present in the first index register (ind1) during the reading command. ∘ a type (T, T') of the variable (Z) seen by the program during the reading command, and ∘ the value (V, V') of the variable (Z) present in the execution stack (P1) and/or of the addressing datum (A, A') present in the first index register (ind1) during the reading command. <EOS>