Clipboard Crash Fix


One of the last parts of the Macintosh system software to be finished before freezing the ROM in September 1983 was the clipboard manager, the code responsible for enabling cut and paste between applications. The clipboard manager provided simple calls to access and manipulate the clipboard, a memory buffer storing the last cut or copied data. Its trickiest aspect was managing memory when an application quit.

The clipboard buffer resided in an application’s heap—the primary memory area available to it. When an application terminated, its heap was deallocated before a new one was assigned to the next application. During this gap—when no application heap existed—the clipboard manager had to preserve the clipboard data.

Our first idea was to write the clipboard to disk between applications. This worked but was unreliable: the Macintosh had no fixed disk, and a floppy might not be present or could be write-protected. We then tried copying the clipboard to the system heap, which persisted across applications, but the clipboard was often too large to fit. Ultimately, we copied it to the stack—a large high-memory region for application variables and runtime state (e.g., return addresses)—where it remained until copied into the new application’s heap.

A few weeks after the ROM was frozen, Apple held a sales rollout presentation to prepare the sales team for the Macintosh launch. While the event included typical sales hype, the highlight was hands-on training: each salesperson tried the Mac for the first time, guided through a demo teaching mouse use and basic apps—MacWrite, MacPaint, and the Finder.

The demo climax involved loading a MacPaint document, selecting an area, copying it to the clipboard, launching MacWrite, and pasting the image into a document—seamlessly mixing text and graphics, impressive at the time. Susan Kare had designed a detailed sneaker illustration for the Macintosh brochure, which became the demo image. Users were to select, copy, and paste the sneaker into MacWrite.

I was invited to the presentation but couldn’t attend—I was still working frantically with the software team to finish the system for the January launch. One afternoon, I got a panicked call from a sales team member.

"We’ve got a problem!" he said. "The sneaker demo crashes—sometimes it works, sometimes it doesn’t. It’s unpredictable, but when it fails, it’s catastrophic: as soon as you quit MacPaint, the screen goes crazy and the machine reboots. We’ll have to skip the cut-and-paste part unless you fix it fast."

I hung up and began thinking through the issue. While describing it aloud, I stopped mid-sentence—I realized the cause. After quitting an app, the clipboard manager copied the clipboard to the stack by subtracting its size from the stack pointer, then copying data into the allocated space. I saw the flaw: about half the time, the clipboard size was odd, making the stack pointer odd. The 68000 microprocessor could not fetch from odd addresses—it triggered a fault. Since the stack is used for basic processor operations, including exception handling, an odd stack pointer caused recursive faults, crashing the system. It worked half the time simply because clipboard sizes were even half the time; odd sizes caused the described crash.

The fix was simple: round up the clipboard size to an even number. But the bug was in ROM, already cast in silicon—this was the first major ROM bug we knew of. I feared we’d need a new ROM version. But Larry Kenyon had devised a clever workaround: patching system traps. While we’d planned to replace entire system calls, Larry proposed a finer method—patching the first trap called before or after the problem code. This allowed us to intercept system calls and inject corrective code.

Using Larry’s method, I wrote a patch for the odd stack issue. He helped integrate it into the System file, loading it at boot. We created a floppy with the updated System file, flown to the sales event by a departing sales manager. But the fix took time to spread. For weeks, I braced myself every time I saw someone cut and paste between apps.