Computer
Walkie-Talkies, Solar Energy Systems Explode Across Lebanon in Second Wave After Pager Attack
Read more of this story at Slashdot.
YouTube Will Use AI To Generate Ideas, Titles, and Even Full Videos
Read more of this story at Slashdot.
Lionsgate Embraces AI in Movie Production To Cut Costs
Read more of this story at Slashdot.
AI Tool Cuts Unexpected Deaths In Hospital By 26%, Canadian Study Finds
Read more of this story at Slashdot.
Microsoft Releases and Patents 'Python In Excel'
Read more of this story at Slashdot.
FDA Grants Neuralink With Breakthrough Device Tag For 'Blindsight' Implant
Read more of this story at Slashdot.
CodeSOD: String in your Colon
Anders sends us an example which isn't precisely a WTF. It's just C handling C strings. Which, I guess, when I say it that way, is a WTF.
while(modPath != NULL) { p = strchr(modPath, ':'); if(p != NULL) { *p++ = '\0'; } dvModpathCreate(utSymCreate(modPath)); modPath = p; } while(modPath != NULL);We start with a variable called modPath which points to a C string. So long as modPath is not null, we're going to search through the string.
The string is in a : separated format, e.g., foo:bar:goo. We want to split it. This function does this by being very C about it.
It uses strchr to find the address of the first colon. If we think about this in C strings, complete with null terminators, it looks something like this:
"foo:bar:goo\0" ^ ^ | | | p modPathWe then replace : with \0 and increment p, doing a "wonderful" blend of using the dereference operator and the post-increment operator and an assignment to accomplish a lot in one line.
"foo\0bar:goo\0" ^ ^ | | | p modPathSo now, modPath points at a terminated string foo, which we then pass down through some functions. Then we set it equal to p.
"foo\0bar:goo\0" ^ | p modPathThis repeats until strchr doesn't find a :, at which point it returns NULL. Our loop is guarded by a check that modPath (which gets set equal to p) can't be null, so that breaks us out of the loop.
And enters us immediately into another, single line loop with no body, which immediately exits as well. I suspect that originally this was written as a do{}while, and then someone realized that it could just be a plain while{}, and completely forgot to remove the second while clause.
This is, honestly, a pretty common idiom in C. It's arguably wrong to even put it here; aside from the bad while clause, you'll see this kind of string handling all the time. But, maybe, that is the WTF.
[Advertisement] Continuously monitor your servers for configuration changes, and report when there's configuration drift. Get started with Otter today!Windows Media Player and Silverlight Are Losing Legacy DRM Services on Windows 7 and 8
Read more of this story at Slashdot.
New Research Finds Microplastics In the Brain's Olfactory Bulb
Read more of this story at Slashdot.
Google Will Begin Labeling AI-Generated Images In Search
Read more of this story at Slashdot.
Snap's New Spectacles Inch Closer To Compelling AR
Read more of this story at Slashdot.
Apple Pulls iPadOS 18 For M4 iPad Pro After Bricking Complaints
Read more of this story at Slashdot.
Final Fantasy 16 Producer Asks Fans Not To Make 'Offensive Or Inappropriate' Mods
Read more of this story at Slashdot.
Instagram Makes All Teen Accounts Private
Read more of this story at Slashdot.
Mozilla Exits the Fediverse, Will Shutter Its Mastodon Server In December
Read more of this story at Slashdot.
TCL Accused of Selling Quantum Dot TVs Without Actual Quantum Dots
Read more of this story at Slashdot.
Salesforce's New AI Strategy Acknowledges That AI Will Take Jobs
Read more of this story at Slashdot.
Desktop Hypervisors Are Like Buses: None for Ages, Then Four at Once
Read more of this story at Slashdot.
IBM Acquires Kubernetes Cost Optimization Startup Kubecost
Read more of this story at Slashdot.
Exploding Pagers Injure Thousands Across Lebanon
Read more of this story at Slashdot.