Saturday, June 23, 2007

Stanford T-Shirts

riki is back again. He's just graduated from Stanford and will continue his happy life in New York this autumn. He bought me a Stanford T-shirt, but I really didn't know if I dare to wear it...

Friday, June 15, 2007

Recursive Destruction and Stack Overflow

Here's something stupid for C++. I was testing an algorithm using a trie implemented by std::list on some data today, which resulted in a very deep tree. At exit the program crashed, due to recursive destruction: std::list destroyed all its elements, which were also tries. There is a similar vulnerability in PHP, though they use C rather than C++. I'm still wondering how to do this in C++. Pool design may be much better in such cases, especially for parse trees. I think I have discussed this with Nirvana when we were implementing a bencode parser several months ago.

Sunday, June 03, 2007

Building PCRE on Windows

My environment is Visual Studio 2005 on Windows Vista for PCRE 7.1. Since PCRE is written in ANSI C, just follow instructions in the doc NON-UNIX-USE. Remember to turn off some macros in config.h such as HAVE_UNISTD_H.

Two weird things here:

1. Define macro NO_RECURSE in config.h if necessary; otherwise running test on data "testinput2" would fail with stack overflow. The current GnuWin32 PCRE 7.0 suffers from this problem.

2. Add a call to _set_printf_count_output(1) at the beginning of main in pcregrep.c; by default VC CRT does not support the format "%n" and the program pcregrep.exe using such format would crash.