Skip to main content

The KISS Principle

“Keep It Simple, Sweetheart“ sounds easy enough to do, but in many ways, this is not a simple world. I do, however, enjoy simplifying things. (-:

Facing this rotten, ancient C program, having it segfault after a few minor changes for no obvious reason, I began to feel a bit stupid.

So... what happens when “We believe that we are stupid?

The curious thing about this belief is that it has been inflicted upon us by somebody else. We would have no concept of stupidity if someone had not told us about it & applied the adjective to us.

So reckons Diana Beaver, an educational researcher.

After discussing life for a bit with someone I seriously value, in which I learned that being “The Crazy Grandpa” is acceptable, but that I am very much not stupid, I decided to apply KISS.

It wasn’t working. Why not? I’d made only a few changes, so the reason is likely to be simple.

Back to the basics.

I sat down & pored through every line of code I was dealing with, rapidly (by #if 0-ing out sections temporarily to see if the rest worked) isolated it to within one function that I had barely touched.

In order for a problem to be made simple, one must understand it. Not always in excruciating detail, but it must be understood, So I began reading statement by statement to be sure that I understood it.

One of the local variables was char *buf[39];, which is an unusually specific value. It turned out that original author had sprintfed a %-38.38s into it. If that overflowed, it wrote text onto the next item in memory: the call-return address on the stack. Off to hyperspace in an instant!

One of my additions produced a 40-character (-byte) string. So... cw80<Esc> then make (which itself only became possible on Sunday), fixed.

The other problem appeared to be where an early routine called a date-interpreting function (which fetched a date stored as a string, hand-scrolled the month digits to the beginning of the string, hand-terminated it there, then returned an atoi ( ) of it).

Careful research discovered that the if ( ) statement this expression was embedded within first checked a string variable (from the argv [ ] array) for a specific value. If no value was supplied, the result was strcmp (NULL, "word"); which of course segfaulted as it attempted to fetch characters from address zero.

Fixed.

Simple can be quite satisfying. (-:

Comments

GregoryO said…
One wonders if the original coder had any experience or training, or simply chose to ignore them. I'm not even a programmer and I, from your musings, could identify and fix gaping holes in this code!
Major said…
Unix-like operating systems have a really great tool for dealing with programs like that. Its called "rm".
Leon RJ Brooks said…
Major, that sounds like the Naive Interface, which when asked “How do I make more space in this directory?” responded “Type rm *”

That would be my favourite solution as well, but I have not yet managed to sell the idea to the business concerned.
Leon RJ Brooks said…
Greg, I doubt that he had any... & in that guy’s case, admitting it would be about the last thing he’d do. (-:

Popular posts from this blog

An Open and Shut response to Darl McBride

Hi, Darl. I see you’re being dishonest again . It’d be really nice if you could shoot straight for a change, but I think Kerry’s Dad will be selling snowplows in Hell first. Three years ago, when I first joined The SCO Group, we focused the company on the area that was most profitable and provided the most benefit to customers, investors, resellers, developers and employees: UNIX No, you focused the company on suing people, which was most profitable to lawyers and provided some golden parachutes for your buddies. People thought we were crazy. They were right. But since SCO owns the UNIX operating system The SCO Group does not own UNIX® in any sense of the word. The Open Group owns the UNIX trademark, definition and other rights , The SCO Group does not. The SCO Group doesn’t even own the UnixWare® or OpenServer® code, the rights to those are held by Novell and TSG use them only by permission and under certain conditions — which they have violate...

5x7 text dot-matrix in five minutes...

This is a fairly primitive toy I threw together today for a specific purpose, published in case it’s any use to others... feed it a list of words as command arguments, which it will then display as a 5x7 ASCII dotmatrix with ‘#’ as a dot & ‘_’ as a blank. /* * display text using a 5x7 bitmap font in ASCII letters */ static unsigned char font [] [5] = { { 0x00,0x00,0x00,0x00,0x00 }, // 0x20 32 { 0x00,0x00,0x6f,0x00,0x00 }, // ! 0x21 33 { 0x00,0x07,0x00,0x07,0x00 }, // " 0x22 34 { 0x14,0x7f,0x14,0x7f,0x14 }, // # 0x23 35 { 0x00,0x07,0x04,0x1e,0x00 }, // $ 0x24 36 { 0x23,0x13,0x08,0x64,0x62 }, // % 0x25 37 { 0x36,0x49,0x56,0x20,0x50 }, // & 0x26 38 { 0x00,0x00,0x07,0x00,0x00 }, // ' 0x27 39 { 0x00,0x1c,0x22,0x41,0x00 }, // ( 0x28 40 { 0x00,0x41,0x22,0x1c,0x00 }, // ) 0x29 41 { 0x14,0x08,0x3e,0x08,0x14 }, // * 0x2a 42 { 0x08,0x08,0x3e,0x08,0x08 }, ...

Citizens Augmenting Government Waste

So here we have Microsoft-funded “ Citizens Against Government Waste ” (CAGW) heavily criticising Massachusetts’s switch to an internationally accepted and open document standard (not open source, open standard — but I seem to remember a large monopolist who frequently confuses the two when it suits them). I remember CAGW, they were the organisation who had dead people writing in to support Microsoft in court a few years ago — thanks to sbergman27 for the link — is this “the dead hand of CAGW” at work again? Let’s follow the money and find out. Who stands to lose the most money and control if Massachusetts switches to an unencumbered document format? Big surprise, it’s CAGW sponsor Microsoft, through their dominant MS-Office suite. Why did CAGW list Microsoft’s suite last, after two other much-less-dominant examples which are waning anyway? If you’re inclined to wallow in additional irony, consider that at leas...