Feed aggregator
Chinese Spies Spent Months Inside Aerospace Engineering Firm's Network Via Legacy IT
Read more of this story at Slashdot.
House Committee Approves Bill Requiring New Cars To Have AM Radio
Read more of this story at Slashdot.
YouTube Launches Communities, a Discord-Like Space For Creators and Fans
Read more of this story at Slashdot.
OpenAI Threatens To Ban Users Who Probe Its 'Strawberry' AI Models
Read more of this story at Slashdot.
23andMe Board Resigns in New Blow To DNA-Testing Company
Read more of this story at Slashdot.
IBM is Quietly Axing Thousands of Jobs
Read more of this story at Slashdot.
Apple and Google Diverge on Photography Philosophy
Read more of this story at Slashdot.
Global Police Dismantle Encrypted Messaging App Used By Criminals
Read more of this story at Slashdot.
Federal Reserve Cuts Rates By Half a Point and Signals Era of Easing Has Begun
Read more of this story at Slashdot.
US Government 'Took Control' of a Botnet Run by Chinese Government Hackers, Says FBI Director
Read more of this story at Slashdot.
LinkedIn Is Training AI on User Data Before Updating Its Terms of Service
Read more of this story at Slashdot.
Fossil Fuel Companies Sponsor $5.6 Billion in Global 'Sportswashing' Deals
Read more of this story at Slashdot.
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.