Winter 92 - KON & BAL'S PUZZLE PAGE

## KONSTANTIN OTHMER AND BRUCE LEAK

See if you can solve this programming puzzle, presented in the form of a dialog between Konstantin Othmer (KON) and Bruce Leak (BAL). The dialog gives clues to help you. Keep guessing until you're done; your score is the number to the left of the clue that gave you the correct answer. These problems are supposed to be tough. If you don't get a high score, at least you'll learn interesting Macintosh trivia.

KON I wrote this program that crashes with a bus error and I can't figure out what's going wrong.

BAL If it's crashing with a bus error, that's easy: just figure out where the bogus bus error address came from.

110 KON Well, that's the problem. I look around and there's not a bad address anywhere.

BAL Let me see.

105 KON OK.

```Bus Error at 1B586
1B582	BFEXTU (A3){D6; \$00}, D0
1B588	MOVE.L(A2)+,D1```

Register A3 has \$70E368, and A2 has \$70DEDC. So that's your puzzle; what do you do now?

BAL Hmmm. Suppose I trace a few times.

100 KON No problem; everything seems to work OK.

BAL What if I type "Go" and hope for the best?

95 KON You crash immediately with an address error at \$1B5A4. The code is trying to do an RTS, but the stack is trashed.

BAL Well that's just a little ways down from where I was before. Anything funny happening in between?

90 KON Nope, just a loop that doesn't touch the stack or anything.

BAL Was the stack OK when I crashed the first time?

85 KON No, the top address on the stack was garbage.

BAL OK, so I run the program again and break just before this routine gets called and check the stack.

80 KON The stack is OK. Everything looks fine. You're at a JSR (A0).

BAL Is A0 OK?

75 KON Yep, it points to the code you were looking at before--at \$1B582.

BAL So I step in and look at the stack.

70 KON You crash immediately with a bus error at \$82.

BAL Huh? Sounds like someone jumped to \$0.

65 KON A0 looked OK. It was just doing a JSR (A0).

BAL Some weird MacsBug bug?

60 KON In this case, no.

BAL All I did was step into a subroutine and I crash somewhere totally different?

55 KON Pretty cool, huh?

BAL Are the registers OK? What does the stack look like?

50

KON Garbage everywhere. The stack has all kinds of noise on it, and the registers seem pretty fragged.

BAL Hmmm. I try it again; this time I set a breakpoint a few instructions before the JSR (A0).

KON OK.

BAL Is everything OK?

45 KON The registers, stack, and code look OK.

BAL So I trace a few instructions, up to the JSR.

40 KON You crash immediately after the first trace with a bus error at \$0104B0CA.

BAL Well that address is garbage. Was it in any register or on the stack before I traced?

35 KON Nope.

BAL What happened to the stack?

30 KON There's 56 extra bytes on it now.

BAL What? Is my machine possessed?

KON It's just a computer.

BAL Some interrupt nastiness happening?

25 KON When you crash, you're at interrupt level 1.

BAL Now we're getting somewhere. Does MacsBug enable interrupts when I trace?

20 KON Yes.

BAL So where's the level 1 interrupt vector kept?

15 KON \$64.

BAL I DM it and see if it's OK.

10 KON It's \$104B07C. Pretty close to where you crashed.

BAL So it sounds like someone is trashing the interrupt vectors, and all the interrupts are held pending when I'm in MacsBug. As soon as I do anything that returns control to the Macintosh, I blow up. So I step spy on \$64 and see who trashes it.

0 KON It's a routine that assumed a buffer was being allocated but wasn't. So the buffer pointer was NIL, and the routine wrote all over low memory, including the exception vectors.

BAL Nasty.

KON Yeah. So how could you catch this before the vectors get trashed?

BAL Doesn't EvenBetterBusError catch writes to NIL?

KON Only at VBL time, and the chances of a VBL interrupt happening before the VBL vector gets trashed are mighty slim.

BAL You could initialize pointer variables to a bus error number like \$50FFC001 instead of NIL. If you did that, you'd crash at the write and know immediately what was wrong.

KON Cool.

KONSTANTIN OTHMER AND BRUCE LEAK As a mere lad, Bruce pulled the programmer's key out of the stone and swore allegiance to the Lady of the Leak. Years later, while good King Bruce was doing penance for his wandering ways, young KON of Locksley had to defend the crown against the Mongol hordes attempting to draw directly to the screen. Upon his return, King Bruce declared, "Let there be time," and there was. Today young KON and his sovereign do battle against the forces of evil lurking in your local heap.*

SCORING

• 100-110 Be honest.
• 75-95 Next time we find a bug, we're  calling you .
• 50-70 So this has happened to you!
• 25-45 No doubt about it, these puzzles are tough.
• 0-20 Well, maybe next time . . . *

Thanks to Scott Douglass for reviewing this column.*

Community Search:
MacTech Search:

Printopia 3.0.8 - Share Mac printers wit...
Run Printopia on your Mac to share its printers to any capable iPhone, iPad, or iPod Touch. Printopia will also add virtual printers, allowing you to save print-outs to your Mac and send to apps.... Read more
BetterTouchTool 2.417 - Customize multi-...
BetterTouchTool adds many new, fully customizable gestures to the Magic Mouse, Multi-Touch MacBook trackpad, and Magic Trackpad. These gestures are customizable: Magic Mouse: Pinch in / out (zoom... Read more
Mellel 4.1.0 - The word processor for sc...
Mellel is the leading word processor for OS X and has been widely considered the industry standard for long form documents since its inception. Mellel focuses on writers and scholars for technical... Read more
ScreenFlow 7.3 - Create screen recording...
ScreenFlow is powerful, easy-to-use screencasting software for the Mac. With ScreenFlow you can record the contents of your entire monitor while also capturing your video camera, microphone and your... Read more
Dashlane 5.9.0 - Password manager and se...
Dashlane is an award-winning service that revolutionizes the online experience by replacing the drudgery of everyday transactional processes with convenient, automated simplicity - in other words,... Read more
ForkLift 3.2 - Powerful file manager: FT...
ForkLift is a powerful file manager and ferociously fast FTP client clothed in a clean and versatile UI that offers the combination of absolute simplicity and raw power expected from a well-executed... Read more
Cocktail 11.5 - General maintenance and...
Cocktail is a general purpose utility for macOS that lets you clean, repair and optimize your Mac. It is a powerful digital toolset that helps hundreds of thousands of Mac users around the world get... Read more
Hazel 4.2.4 - Create rules for organizin...
Hazel is your personal housekeeper, organizing and cleaning folders based on rules you define. Hazel can also manage your trash and uninstall your applications. Organize your files using a familiar... Read more
Skype 8.18.0.6 - Voice-over-internet pho...
Skype allows you to talk to friends, family, and co-workers across the Internet without the inconvenience of long distance telephone charges. Using peer-to-peer data transmission technology, Skype... Read more
Backup and Sync 3.40.8921.5350 - File ba...
Backup and Sync (was Google Drive) is a place where you can create, share, collaborate, and keep all of your stuff. Whether you're working with a friend on a joint research project, planning a... Read more

## Latest Forum Discussions

Destiny meets its mobile match - Everyth...
Shadowgun Legends is the latest game in the Shadowgun series, and it's taking the franchise in some interesting new directions. Which is good news. The even better news is that it's coming out tomorrow, so if you didn't make it into the beta you... | Read more »
How PUBG, Fortnite, and the battle royal...
The history of the battle royale genre isn't a long one. While the nascent parts of the experience have existed ever since players first started killing one another online, it's really only in the past six years that the genre has coalesced into... | Read more »
Around the Empire: What have you missed...
Oh hi nice reader, and thanks for popping in to check out our weekly round-up of all the stuff that you might have missed across the Steel Media network. Yeah, that's right, it's a big ol' network. Obviously 148Apps is the best, but there are some... | Read more »
All the best games on sale for iPhone an...
It might not have been the greatest week for new releases on the App Store, but don't let that get you down, because there are some truly incredible games on sale for iPhone and iPad right now. Seriously, you could buy anything on this list and I... | Read more »
Everything You Need to Know About The Fo...
In just over a week, Epic Games has made a flurry of announcements. First, they revealed that Fortnite—their ultra-popular PUBG competitor—is coming to mobile. This was followed by brief sign-up period for interested beta testers before sending out... | Read more »
The best games that came out for iPhone...
It's not been the best week for games on the App Store. There are a few decent ones here and there, but nothing that's really going to make you throw down what you're doing and run to the nearest WiFi hotspot in order to download it. That's not to... | Read more »
Death Coming (Games)
Death Coming 1.1.1.536 Device: iOS Universal Category: Games Price: \$1.99, Version: 1.1.1.536 (iTunes) Description: --- Background Story ---You Died. Pure and simple, but death was not the end. You have become an agent of Death: a... | Read more »
Hints, tips, and tricks for Empires and...
Empires and Puzzles is a slick match-stuff RPG that mixes in a bunch of city-building aspects to keep things fresh. And it's currently the Game of the Day over on the App Store. So, if you're picking it up for the first time today, we thought it'd... | Read more »
What You Need to Know About Sam Barlow’s...
Sam Barlow’s follow up to Her Story is #WarGames, an interactive video series that reimagines the 1983 film WarGames in a more present day context. It’s not exactly a game, but it’s definitely still interesting. Here are the top things you should... | Read more »
Pixel Plex Guide - How to Build Better T...
Pixel Plex is the latest city builder that has come to the App Store, and it takes a pretty different tact than the ones that came before it. Instead of being in charge of your own city by yourself, you have to work together with other players to... | Read more »

## Price Scanner via MacPrices.net

Back in stock! Apple’s full line of Certified...
Save \$300-\$300 on the purchase of a 2017 13″ MacBook Pro today with Certified Refurbished models at Apple. Apple’s refurbished prices are the lowest available for each model from any reseller. A... Read more
Back in stock: 13-inch 2.5GHz MacBook Pro (Ce...
Apple has Certified Refurbished 13″ 2.5GHz MacBook Pros (MD101LL/A) available for \$829, or \$270 off original MSRP. Apple’s one-year warranty is standard, and shipping is free: – 13″ 2.5GHz MacBook... Read more
Apple restocks Certified Refurbished 2017 13″...
Apple has Certified Refurbished 2017 13″ MacBook Airs available starting at \$849. An Apple one-year warranty is included with each MacBook, and shipping is free: – 13″ 1.8GHz/8GB/128GB MacBook Air (... Read more
8-Core iMac Pro on sale for \$4699, save \$300
Amazon has the 8-core iMac Pro on sale for \$4699 including free shipping. Their price is \$300 off MSRP, and it’s the currently lowest price available for an iMac Pro. For the latest up-to-date prices... Read more
10″ 512GB WiFi iPad Pros on sale for \$849, sa...
B&H Photo has Space Gray and Rose Gold 10.5″ 512GB WiFi iPad Pros on sale for \$849. Their price is \$150 off MSRP, and it’s the lowest price available for these models, new, from any Apple... Read more
MacBook Pro sale! B&H drops prices on new...
B&H Photo has dropped prices on new 2017 13″ MacBook Pros, with models now on sale for up to \$200 off MSRP. Shipping is free, and B&H charges sales tax for NY & NJ residents only. Their... Read more
13″ MacBook Airs on sale for \$100-\$150 off MS...
B&H Photo has 13″ MacBook Airs on sale for \$100-\$150 off MSRP. Shipping is free, and B&H charges sales tax for NY & NJ residents only: – 13″ 1.8GHz/128GB MacBook Air (MQD32LL/A): \$899, \$... Read more
Huge iMac sale! Apple reseller now offering 2...
B&H Photo has new 2017 21″ & 27″ iMacs on sale today for up to \$300 off MSRP. Shipping is free, and B&H charges sales tax for NY & NJ residents only: – 27″ 3.8GHz iMac (MNED2LL/A): \$... Read more
Sale! 1.4GHz Mac mini for \$399, \$100 off MSRP
B&H Photo has the 1.4GHz Mac mini on sale for \$399 for a limited time. Their price is \$100 off MSRP, and it’s the lowest price available for a mini from any Apple reseller: – 1.4GHz Mac mini (... Read more
Sale of the year continues as Apple resellers...
Adorama has new 2017 15″ MacBook Pros on sale for \$250-\$300 off MSRP. Shipping is free, and Adorama charges sales tax in NJ and NY only: – 15″ 2.8GHz Touch Bar MacBook Pro Space Gray (MPTR2LL/A): \$... Read more

## Jobs Board

*Apple* Retail - Multiple Positions - Apple,...
Sales Specialist - Retail Customer Service and Sales Transform Apple Store visitors into loyal Apple customers. When customers enter the store, you're also the Read more
Data Scientist, *Apple* Ecosystem (AMP Anal...
# Data Scientist, Apple Ecosystem (AMP Analytics) Job Number: 113428728 Santa Clara Valley, California, United States Posted: 24-Jan-2018 Weekly Hours: 40.00 **Job Read more
*Apple* Professional Learning Specialist - A...
# Apple Professional Learning Specialist Job Number: 113456892 Englewood, NJ, New Jersey, United States Posted: 02-Feb-2018 Weekly Hours: 40.00 **Job Summary** The Read more
*Apple* Retail Online, Senior Financial Anal...
# Apple Retail Online, Senior Financial Analyst Job Number: 57228835 Santa Clara Valley, California, United States Posted: 12-Feb-2018 Weekly Hours: 40.00 **Job Read more
Site Reliability Engineer, *Apple* Pay - Ap...
# Site Reliability Engineer, Apple Pay Job Number: 113356036 Santa Clara Valley, California, United States Posted: 12-Jan-2018 Weekly Hours: 40.00 **Job Summary** Read more