Do you remember these once common but now vanishing cars? The show dedicated to dull motors from the past
Change to bin collections for 160 Maldon homes after roadworks disruption
Tissues at the ready! David Attenborough captures tear-jerking moment between mother gorilla and her newborn baby in BBC documentary Parenthood
Tsunami update issued for Liverpool pre-season friendly in Japan with Arne Slot's side set to face Yokahama TODAY despite major warning after 8.8-magnitude earthquake hit Russia
Mark Clattenburg accuses ex-Chelsea star John Obi Mikel of 'swinging PUNCHES' at him in new revelations about 2012 clash - and claims Blues wanted 'payback' for John Terry race row
How long does it take for a tsunami to hit after an earthquake? Timelapse reveals minute-by-minute breakdown
Essex teen, 15, charged after attack in Halstead Co-op supermarket
Cisco donates Agntcy project to Linux Foundation in the hope it gets AI agents interacting elegantly
Cisco's Agntcy project is the latest AI framework to find refuge at the Linux Foundation.…
Inside the '£19MILLION holiday lodge scam': How hundreds of Brits poured their hard-earned savings into 'schemes' - and walked away with nothing
Four people found dead after abandoning baby on front lawn
Life inside Britain's 'poshest' migrant hotel: Asylum seekers enjoy breakfast buffet, four-poster beds, video games and alcohol
A Pill for Sleep Apnea Could Be on the Horizon
Read more of this story at Slashdot.
I have my Christmas presents wrapped and ready to go in July - here's how I did it
Myleene Klass recalls the horrifying moment Harvey Weinstein offered her a sex contract to make her famous and reveals her fear of being unable to escape his advances
Moment furious motorist blows up as he denies scratching car in alleged crash - while other driver insists they have 'matching' scratches
My daughter killed herself after her depression spiralled following a workplace injury at River Island - I blame the fashion firm
Essex dad’s warning after young son’s wobbly tooth leads to cancer diagnosis
Australia bans kids from signing up for YouTube accounts, angering Google
Australia will require Google to ensure that children aged under 16 cannot sign up for YouTube accounts.…
Boy with 'peculiar' wobbly tooth diagnosed with aggressive disease
CodeSOD: Going on a teDa
Carlos G found some C++ that caused him psychic harm, and wanted to know how it ended up that way. So he combed through the history. Let's retrace the path with him.
Here was the original code:
void parseExpiryDate (const char* expiryDate) { // expiryDate is in "YYMM" format int year, month; sscanf(expiryDate, "%2d%2d", &year, &month); //... }This code takes a string containing an expiry date, and parses it out. The sscanf function is given a format string describing two, two digit integers, and it stores those values into the year and month variables.
But oops! The expiry date is actually in a MMYY format. How on earth could we possibly fix this? It can't be as simple as just swapping the year and month variables in the sscanf call, can it? (It is.) No, it couldn't be that easy. (It is.) I can't imagine how we would solve this problem. (Just swap them!)
void parseExpiryDate(const char* expiryDate) { // expiryDate is in "YYMM" format but, in some part of the code, it is formatted to "MMYY" int year, month; char correctFormat[5]; correctFormat[0] = expiryDate[2]; correctFormat[1] = expiryDate[3]; correctFormat[2] = expiryDate[0]; correctFormat[3] = expiryDate[1]; correctFormat[4] = '\0'; sscanf(correctFormat, "%2d%2d", &year, &month); //... }There we go! That was easy! We just go, character by character, and shift the order around and copy it to a new string, so that we format it in YYMM.
The comment here is a wonderful attempt at CYA. By the time this function is called, the input is in MMYY, so that's the relevant piece of information to have in the comment. But the developer really truly believed that YYMM was the original input, and thus shifts blame for the original version of this function to "some part of the code" which is shifting the format around on them, thus justifying… this trainwreck.
Carlos replaced it with:
void parseExpiryDate (const char* expiryDate) { // expiryDate is in "MMYY" format int month, year; sscanf(expiryDate, "%2d%2d", &month, &year); //... } .comment { border: none; }