Thursday, October 27, 2005

integer overflow in operator new[]

Does it come as a surprise that array allocation can cause an integer overflow? Not really. My tests with GCC 4 on Linux show that many array allocation operations are affected:

size_t large_n
= std::numeric_limits<size_t>::max()
/ 0x10 + 2;
struct A { int a, b, c, d; }; // 0x10 bytes

void test() {
{
A * arr = new A[large_n];

// succeeds, but what does it mean?
arr[5000].a = 10;
}

{
// a clear overflow
A * arr = (A*) malloc(large_n * sizeof(A));
}

{
A * arr = (A*) calloc(large_n, sizeof(A));

// SEGFAULT
arr[5000].a = 10;
}

{
// bad_alloc - correct behavior
vector<a> arr(large_n);
}
}

Notice, that vector<> behaves as expected. Again C++ standard library shows its superiority to the conventional "do it yourself" methods. This is just another reason to use vector<> everywhere where an array is needed.

Thursday, September 22, 2005

Disable hibernation from the command line

Power configuration dialog got somewhat tricky in Vista. I never needed hibernation but I couldn't figure out how to disable it to save some disk space. Here is a better method:

powercfg -h off

This util has many other useful options as well.

Monday, September 19, 2005

Monday, July 11, 2005

Russian ship in Tacoma WA

A magnificent ship show was held in Tacoma WA on July 4'th. A russian ship "Pallada" was exibited among many fine ships. Here are some pictures:






Friday, June 03, 2005

How to make ipw2100 module work with suspend/resume

ipw2100 module needs to be removed from the kernel before suspending. Otherwise it won't be operational on resume. To accomplish that something like this needs to be added to /etc/acpi/actions/sleep file:

#!/bin/bash
if grep -q closed /proc/acpi/button/lid/LID/state
then
/sbin/modprobe -r ipw2100
echo -n "mem" > /sys/power/state
/sbin/modprobe ipw2100
/sbin/ifup eth1
fi

Tuesday, March 01, 2005

Michael Waller and his views on world politics

I discovered this guy recently. He gave an interview on the “O’Reilly Factor” on Putin. It was immediately clear that he gives very valuable insights into Russian politics. It turns out he wrote a number of papers about Putin, KGB and Russia. I read some of them. A good, solid material. He also maintains a blog. Very recommended.

Links:
Blog
The Institue of World Politics
Waller's page at the Institute of World Politics

Friday, February 04, 2005

Where the spam comes from

Recently I found that some e-mail from Russia doesn't reach my Verizon e-mail account. From other sources I heard that Verizon blocks e-mail coming from certain countries because a large ammount of spam originates there. Or so Verizon thinks. To test their assumptions I conducted a small experiment. I collected statistics for the country of origin of spam e-mail for my Hotmail account. Of course I didn't take my Verizon account because the statistics would be skewed. So here are the results:

USA 27 57%
Korea 5 11%
China 4 9%
Hong Kong 2 4%
Canada 2 4%
Thailand 2 4%
Japan 1 2%
Uruguay 1 2%
Wales 1 2%
Qatar 1 2%
Total 47

So now you know. Keep in mind that the result from Hotmail can also be skewed. Hotmail is free to block e-mail too. But I haven't notice it doing anything like that. On the contrary with Verizon it's obvious. And yes, I turned Verizon spam filter off. POP3 and Verizon filter just don't play along.

For spam coming from the USA, the distribution along the major network providers looks like this:

AOL830%
Comcast415%
Qwest27%
Verizon14%
Other1244%

Tuesday, February 01, 2005

Linux on Tablet PCs

Here are some links I collected:

  1. Toshiba M200, Debian
  2. Toshiba M200, Mandrake 9.2
  3. Compaq TC1000, Debian
  4. LG Electronics LT-20, Xandros
  5. Acer C110

BTW, I myselft have FC2 on Toshiba M200. I'm planning to write about my advanture of installing it. Of course it runs side-by-side with WinXP.

Monday, January 31, 2005

Election in Iraq succeeded and this is a Good Thing.

It was a truely great day for Iraqi people. The day the history was being made.

Win32 GUI Generics library rocks!

If you haven't seen this library from John Torjo, you definitely ought to. It represents the Win32 GUI programming at its best. The template stuff is used a lot. And the result is a powerful yet easy to use and understand library.

Here are a couple of links: the library, articles. Also check John's articles in the CUJ. They explain quite a few things of the library design.

(PS: I just understood how the library handles event binding internally. It made me think good about myself :). It's nothing difficult, but kind of indirect.)

Tuesday, January 11, 2005

C/C++ User Journal content is now available online

What a surprise! If you noticed the CUJ site has changed. And this is a good change. Now you can log in and access all articles of the journal online. I've been waiting for this feature for a long long time. You need to be a subscriber to use this feature. I am and I've created my online account today, because I needed to access one article published two years back. Couple of minutes spent on filling a registration form, and here you go I got it.

The other thing is that it comes with access to two other journals: DDJ and Perl Journal. For free, if you are already subscribed to CUJ. And I thought it couldn't get any better!