Archive for September, 2010

Dangerous printf

Friday, September 17th, 2010

It took quite some time until I found this bug. Here’s a simplified version of what caused it:

char dir[2048];
GetCurrentDirectory(2048, dir);
printf(CString("Current dir is:")+dir));

That’s doesn’t look bad, does it? And (like in the great programmer quotes), it works on my computer. But it doesn’t work if the customer’s current folder is something like “%&┬žsomething”, because it contains %s.

So don’t throw any external data at the first parameter of printf, sprintf, etc; instead put it into the following parameters.

printf(“Current dir is: %s”, dir);

Taking a shortcut

Wednesday, September 1st, 2010

A simple trick to make work a bit easier. Whenever you have folder with a few files and you often need to run a certain program or change to another folder afterward working with the files, create a Windows shortcut in this folder.


The Easy2Sync for Outlook configuration files are in this folder. Whenever I have to mess with them (delete them for a clean-start-test , for example) I will usually want to run Easy2Sync for Outlook afterwards. That’s why I created a shortcut to the program in this folder.

Simple and yet helpful.