4 ms·
If checking if 21 <= day AND 11 <= month AND 21 <= year is the actual logic they used to check if a date is after Nov 21 2021, I'm not sure they should be writi
by icehawk 3y ago
If checking if 21 <= day AND 11 <= month AND 21 <= year is the actual logic they used to check if a date is after Nov 21 2021, I'm not sure they should be writing code that runs on a train.
(Edit: Fixed inequality direction.)
- p_l 3y agoThis is due to IEC 61131-3 environment - they are getting date value as 3 separate variables from system. Similar stuff is common in PLCs all across the world.
- tczMUFlmoNk 3y agoSure, but regardless of input format, the test in GP's comment would indicate that October 22, 2021 is not before November 21, 2021. The right test is something like "year < 21 || year == 21 && (month < 11 || month == 11 && (day <= 21))". And yes, probably refactor that logic for clarity, but from this form you can see that it is not equivalent to the test above.
- p_l 3y agoThe code as deployed has errors (the link actually shows ghidra decompile of relevant portion). Months & days are counted from 1. The error is what makes it so that instead of failing "unfixably" once 2021-11-21 happens, it instead simulates failure between nov. 21 and dec. 1, and dec. 1 and january 1, every year starting with 2021.
- icehawk 3y agoYes. Its that second part that makes me unsure. Not that they're checking month and day and year.
- p_l 3y agoDAY >= 21 AND MONTH >= 11 AND YEAR_2digit >= 21 The condition yields true from 2021 on for: nov. 21 - nov. 30 dec. 21 - dec. 31
- turquoisevar 3y agoThis might be on purpose if they’re merely trying to make the third party maintenance company look unreliable.
- petre 3y agoJust in time for the Christmas rush. This calls for criminal prosecution.
- icehawk 3y agoI reversed the direction of the tests, as pointed out, but the original logic would fail to detect that say June 22, 2022 is after 21 November 2021.
- colanderman 3y ago(you have swapped the direction of the inequalities -- not that it makes the code any more correct)
- lmm 3y agoThey shouldn't, but it's an industry with heavy code quality regulation, which naturally ensures much worse code quality.
- Eisenstein 3y agoI would think any competent software engineer would refuse to write code that could cripple their own nation's civilian transport because of their boss's greed, and thus the company had someone do it who was idiotic enough to try.
- waffleiron 3y agoThere are plenty of competent software engineers that do extremely unethical things for money, look at the defense industry.