3 ms·
I remember learning in my embedded programming class about state machines and how certain states cannot be reached. In the lab, I accounted for every possible
by exabrial 11y ago
I remember learning in my embedded programming class about state machines and how certain states cannot be reached.
In the lab, I accounted for every possible valid state with a transition out to another state.
I left my microcontroller running when I went to get lunch, came back and it was frozen. I did a dump, and discovered it was idling in a state that has no entry into it, and because I had no exit, it would just sit there.
I 'fixed' the problem by adding a transition to reset the controller from every state that shouldn't be reached.
- peterwwillis 11y agoThis is considered a minor security feature. When a program unexpectedly finds itself in a routine, or a routine ends abruptly, it's possible it was a code jump, or the after-effects of a payload... Neither of which are good things.
- TazeTSchnitzel 11y agoIf you use a switch(), have a default:, even if it's seemingly impossible.
- jakub_g 11y agoand print "call Brian" in it (anecdote from a HN thread a month ago): https://news.ycombinator.com/item?id=11397251 https://news.ycombinator.com/item?id=11397251
- StringyBob 11y agoYes - in hardware where faults are expected to be rare it's often a good idea to just detect that something went wrong. If you know something bad happened you can choose to re-run. (E.g. restart using a watchdog timer) Silently jumping back to a default state is sometimes useful, but could result in unpredictability or perhaps silent data corruption for some critical applications.