Skip to main content

CodeSOD: Oh, K?

3 weeks 4 days ago

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; } [Advertisement] Keep all your packages and Docker containers in one place, scan for vulnerabilities, and control who can access different feeds. ProGet installs in minutes and has a powerful free version with a lot of great features that you can upgrade when ready.Learn more.
Remy Porter

Bank of America Kindly Asks That You Don't Share Your Password With Your AI Assistant

3 weeks 4 days ago
Longtime Slashdot reader schwit1 shares a report from TechCrunch: In an email blast to customers titled "Protecting your finances in the Al World," Bank of America urged customers to never share their username and password with another person or an outside service, "including an Al-enabled tool or agent that offers to act on your behalf." [...] A spokesperson for Bank of America confirmed the authenticity of the bank's email that was posted to social media. But heed the bank's warning, for if things go wrong, it's on you. Account agreements at most banks hold customers responsible for anyone they give their log-in to. "If you do share your credentials," its email reads, "keep in mind that you're responsible for activity resulting from that access."

Read more of this story at Slashdot.

BeauHD