Patch seg fault when simulating FET with NULL on gate
authorLukáš Jiřiště <gymnazium.jiriste@gmail.com>
Fri, 16 Feb 2024 21:58:23 +0000 (22:58 +0100)
committerLukáš Jiřiště <gymnazium.jiriste@gmail.com>
Fri, 16 Feb 2024 21:58:23 +0000 (22:58 +0100)
FETs with no connection on gate now default to closed.

src/sim_main.c

index 14cc9b56b48229b098aa9aa9ad70d7c9177199d0..37929e6b13d76f0d224056e6653155ca829f2303 100644 (file)
@@ -1,10 +1,16 @@
 #include "FET_sim.h"
 #include "libft.h"
 
+// Maybe an error should be return when gate is NULL
 static void    update_mosfet(t_mosfet *mosfet)
 {
        t_state state;
 
+       if (!mosfet->gate)
+       {
+               mosfet->is_opened = 0;
+               return ;
+       }
        state = mosfet->gate->state;
        if (mosfet->type == p && state == on)
                mosfet->is_opened = 1;