CodeSOD: Oh, K?
Pierre found this cry for help:
for (j = 0; j < DISTRICT_CARDINALITY; j++) { /* * A poor way to work around some sort of memory * violation. k gets clobbered, so I buffer l with it. * Help? */ for (k = 0, l = 0; k < customers; k++, l++) { /* c_id */ FPRINTF(output, "%d", l + 1); METAPRINTF((output, "%c", delimiter));Honestly, I'm always a little worried in C-like languages when the loop variable isn't scoped to the loop and declared in place. Always concerning, so when there's concerns with clobbering, I'm not surprised.
This iterates across a set of "districts", and then iterates across a list of customers. Standard output functions are replaced with macros, and honestly, I don't know that I want to know what happens in METAPRINTF.
But fine, this iterates across a bunch of stuff and generates output. It's the comment that we're really curious about. "Some sort of memory violation", so we duplicate our loop variable. What on earth could be happening here?
Well, Pierre found the "memory violation", which is probably what you expected:
k = strlen(someOutputString) - 8;k is used elsewhere in the loop as a variable. That's not a memory violation, that's just how variables work.
This leaves us with one possible conclusion: the developer who wrote the comment couldn't find this bug. And given the weird use of macros here, I'm going to go out on a limb and guess that it's not the developer's fault; I strongly suspect the loop is so long, so complicated, and so obfuscated that very few developers could find that.
My earlier complaint about scoping the variable to the loop wouldn't fix this, which I guess is on me. They still should really scope the variable to the loop.
.comment { border: none; }Prison psychologist who allowed lifer to film their sex sessions and smuggled in phones and SIMs in baked bean tins is jailed for 28 months
Parents share footage of their terrified daughter, 8, choking to death on food in school cafeteria as they claim that not enough was done to save her
Britain's most hated road turns 40: The M25 is despised for its delays, variable limits and poor condition... but Britain couldn't function without it
Essex train passengers issued warning to 'plan ahead' as services disrupted
Google's Gemini 4 Carbon looks like a diamond in the rough
Has 'desirable' Sussex city become a hotbed for thuggery? Residents of Chichester concerned at rise in racist and homophobic abuse as theatre cast targeted by hoodlums
PETER HITCHENS: Bizarre case of the dead deer that proves the jobsworth class have forgotten who they are meant to serve
Mysterious pill-shaped UFO caught on camera by pilots flying above Middle America
Boffin's software found a possible dwarf planet - a result so rare he thought it must be a bug
MPs call for vulnerable young women to be prioritised in devolution plans
MPs call for vulnerable young women to be prioritised in devolution plans
Chelmsford care home residents meet Jessie the hawk at birds of prey visit
Tape is so not dead that Fujifilm will increase production capacity 5x
Bank of America Kindly Asks That You Don't Share Your Password With Your AI Assistant
Read more of this story at Slashdot.