Archive for the ‘Computers’ Category

Code Gem of the Day…

Wednesday, September 20th, 2006

I ran across this particular “gem” today in some C code:


char * string = Foo();

if (string == NULL)
{
   string = (char *)malloc(1);
   sprintf(string, "%c", NULL);
}

The intent was to guarantee that “string” contains a C string. This implementation is amazingly stupid for two reasons.

  1. It is really inefficient. What they really wanted on the sprintf line is string[0] = 0; The sprintf line, requires a function call, requires the stack be set up with the string parameter "%c", and requires the function decode the string to determine how to interpret the optional arguments. The alternative I propose ends up being a couple of assembly instructions, no function call, and certainly no format string being generated.
  2. It overruns the 1 byte buffer they allocated. sprintf null terminates the string it creates, without regard for the size of the buffer you provide for storage, and without regard for the content of the formatting values. A safer way to do this would be to use snprintf, which allows you to specify how much storage you are providing. Or better yet, use the suggestion above.

The whole function that this code was contained in was poorly written, but this “gem” stood out.

Dude, Dell Laptops are da bomb, literally…

Wednesday, June 21st, 2006

It seems quiteliterally given this article illustrating a dell laptop that burst into flames. I wonder what caused it. I recommend HP over Dell, but I’m biased. :)

The Great Reconstruction

Tuesday, November 15th, 2005

The webserver that hosted this site was also recently hosting (albeit temporarily) the Lupper worm. That has been rectified, but it wasn’t simple. There was an installation of awstats on the old server setup that I had mostly forgotten about. While I believe the firewall I had setup on the box prevented any of the backdoors the worm opened from being useful, I couldn’t be certain. I decided to rebuild the box. I chose to use a new gentoo install. After some initial pains with booting the LiveCD (because my CD-ROM doesn’t support DMA), I was off to the races. Slowly. I started on Wednesday of last week, and just managed to turn on the blog again last night.

During the process, I managed to lose all the content to the blog. Luck was on my side, and I managed to recovery it. Wordpress uses MySQL as its backend database. Before I wiped the main drive of the server, I had exported the contents of the database and stored them on a separate drive. After getting gentoo up and running, I “emerge”d apache, MySQL, Wordpress and other stuff I needed. (The virtual hosting in gentoo is well done, btw.)

I was in the process of restoring my database and made a one character error. Instead of using ”< " to redirect the text file to the mysql command I used ">“ and redirected the output of the mysql command over my text file. One slip of the finger and two years worth of postings were gone. Ouch. I wasn’t pleased.

I managed to figure out that I could dump the unused blocks on the drive using debugfs. I let that go for a while and ended up with an 800MB+ file. A few greps later, and I confirmed my hope: the data was still on the drive. A little more investigation and I found the data was relatively contiguous in the dump file, AND because I hadn’t compressed the mysql dump, I could actually piece it back together. I threw together a couple of C programs. The first chopped out the stuff before my data and the second chopped out the stuff after my data. I ended up with a few megabytes of mostly text data that needed to be cleaned up, and as you can see, it worked.

What have I learned?:

  1. Understand your system
  2. Keep up to date on releases if you are going to have a public website
  3. Make sure backup files are read-only
  4. Don’t make major changes to your setup while tired, or if you do, triple check before hitting “return”

I’m confident managing this system will be much easier now that I am using gentoo. The old server had been running RedHat 8 with lots of stuff hand upgraded by me. Now it is running a 2.6.x kernel, and a sane packaging management solution. Kudos to gentoo. Hooray for being able to go to bed at a sane time again.

Microsoft and Yahoo in IM cooperation

Wednesday, October 12th, 2005

It looks like Microsoft and Yahoo have come to an agreement to make the two IM clients work together. I can say, it certainly is annoying having to have so many clients installed on a given machine.

I find the Yahoo client to have the best ease of use and features of the clients I use. I especially like the integration of the launchcast radio into the client. It is much more convenient than having a separate browser window open. I personally use or have used recently ICQ, MSN Messenger, Google Talk, Yahoo, and Jabber (via Exodus) in different locations.

An amazing thing happened recently

Tuesday, November 30th, 2004

I can’t believe it myself, but I have actually found time to play a game on my computer. I recently found that I still had Warcraft III on my home PC. I couldn’t remember playing it in the recent past, so I looked at the save files. February 2003. That marks the last time I had actually played a game on the PC. This is rather amazing, considering that before I met Lisa, I spent at least 2 hours a weeknight playing computer based games. My life has really changed. I spent part of Sunday night playing, and last night as well. I’m working my way through the Orc campaign. At least that’s where I left off before. It took me about 30 minutes to become reoriented and remember all the details, but I’m feeling pretty confident in the interface now.

My interest was partially sparked by the recent release of World of Warcraft. Unfortunately, my home machine is just too lame to run it. Its time to start saving up for a new one.

Ok, that’s all the update I have time for today… whee!
I’d also like to get Halo 2 for the Xbox. I did find time to play all the way through Halo. I had to do this in the evenings after Morgan went to bed. Both Lisa and I feel pretty strongly that the violent games are inappropriate for Morgan.