• The Old New Thing

    Dead man running


    The plight of the legally dead (but physically alive) in India has been taken up by - of course - a legally dead man. And now he's running for public office. Though apparently this isn't the first time.

    (People are usually declared dead by conniving relatives who want to claim their inheritance prematurely.)

    I wish him luck. If it works in Missouri it can work in India.

  • The Old New Thing

    Is open source the new monoculture?


    Okay I know I'm going to get into a lot of trouble for even bringing up this topic...

    This past weekend, Ulf Harnhammar discovered two buffer overflow and two directory traversal vulnerabilities in LHA, a library of data compression functions.

    Since the code for this is public, it has been copied all over the place. At least one commercial archive management program and at least one commercial mail antivirus program are vulnerable. A denial of service attack is already under way against the mail antivirus program; all you have to do is attach a malformed LHA file to a message, causing the scanner to crash when it attempts to scan the attachment. When the administrator restarts the mail server, the scanner will resume where it left off... and crash again. (Somebody with more time on their hands could craft a more clever LHA file attack that takes over the mail server itself.)

    The fact that the code itself was public meant that everybody didn't have to write their own LHA functions. This is a good thing. However, it also means that everybody has the same security vulnerabilities. This is a bad thing.

    So we have one bug that can take down large numbers of machines, even though they're all running different software.

    How do you track all the versions? Is there a solution to this? Is it even a problem?

  • The Old New Thing

    Truckers block highway to protest high gas prices


    To protest rising gasoline prices, a group of truckers abandoned their vehicles in the middle of the highway. It struck me as odd that a country that brims with anti-French rhetoric would adopt one of their protest techniques.

    Presumably they don't want French gasoline prices either.

  • The Old New Thing

    Why does my hard drive light flash every few second?


    Back in Windows 95, people would notice that their hard drive light would blink every few seconds. What's that all about?

    Actually, it wasn't the hard drive light after all.

    Windows 95 was polling your CD-ROM drive to see whether you had inserted a new CD. Some computers wired up the "hard drive light" not to the hard drive but rather to the SCSI and/or IDE bus. So the light didn't indicate hard drive activity necessarily. It turned on for any bus activity.

    Fortunately, motherboard manufacturers discovered their mistake and nowadays you don't find any of them that miswire the hard drive access light.

    Or do you? I keep my computer under my desk so I never see the hard drive light anyway. I'm just surmising that in the past seven years, motherboard manufacturers have gotten their act together.

  • The Old New Thing

    Today is Swedish tax day


    Of course, in Sweden, every day is tax day.

    By now, it's too late to fill out your tax form, which the Swedish tax agency permits you to file on paper, via Internet, over the phone, or even via SMS.

    They even have what I wish the US tax agency had: An online tax form calculator.

  • The Old New Thing

    You wanted Extreme Crochet?


    Keith Moore thought I was writing about Extreme Crochet in my previous post about Extreme Croquet.

    No, Keith, if I had wanted to write about Extreme Crochet, I would have used this link.

  • The Old New Thing

    Extreme croquet


    This week, Only a Game covered the sport of Extreme Croquet.

    Still doesn't hold a candle to Extreme Ironing, though.

  • The Old New Thing

    Using the echo command to remember what you were doing.


    Sometimes you'll start typing a complex command line and then realize that you can't execute it now. Perhaps you're in the wrong directory or you forgot to map the drive. It would be a shame to hit ESC and lose that command line.

    What I do is edit the line to insert the word "echo" in front, then hit Enter. (Note: This doesn't work if you have command line redirection.)

    This prints the command to the screen, where it can be cut/pasted later. Even more, it enters the line into the command history, so a few uparrows will bring it back.

  • The Old New Thing

    $501 for 510g of peanut butter


    You can buy 510 grams of peanut butter for only $501.

    Of course, this is special peanut butter. It must be kept at -20°C. And it is not intended for human consumption.

    This is peanut butter from the National Institute of Standards and Technology intended for use by food analysis laboratories to calibrate their equipment. For example, standard peanut butter consists of 10.4% ± 0.2% saturated fat.

    (Link courtesy of Slate.)

  • The Old New Thing

    What is __purecall?


    Both C++ and C# have the concept of virtual functions. These are functions which always invoke the most heavily derived implementation, even if called from a pointer to the base class. However, the two languages differ on the semantics of virtual functions during object construction and destruction.

    C# objects exist as their final type before construction begins, whereas C++ objects change type during the construction process.

    Here's an example:

    class Base {
      Base() { f(); }
      virtual void f() { cout << 1; }
      void g() { f(); }
    class Derived : public Base {
      Derived() { f(); }
      virtual void f() { cout << 2; }

    When a Derived object is constructed, the object starts as a Base, then the Base::Base constructor is executed. Since the object is still a Base, the call to f() invokes Base::f and not Derived::f. After the Base::Base constructor completes, the object then becomes a Derived and the Derived::Derived constructor is run. This time, the call to f() invokes Derived::f.

    In other words, constructing a Derived object prints "12".

    Similar remarks apply to the destructor. The object is destructed in pieces, and a call to a virtual function invokes the function corresponding to the stage of destruction currently in progress.

    This is why some coding guidelines recommend against calling virtual functions from a constructor or destructor. Depending on what stage of construction/destruction is taking place, the same call to f() can have different effects. For example, the function Base::g() above will call Base::f if called from the Base::Base constructor or destructor, but will call Derived::f if called after the object has been constructed and before it is destructed.

    On the other hand, if this sample were written (with suitable syntactic changes) in C#, the output would be "22" because a C# object is created as its final type. Both calls to f() invoke Derived::f, since the object is always a Derived. Notice that means a method can be invoked on an object before its constructor has run. Something to bear in mind.

    Sometimes your C++ program may crash with the error "R6025 - pure virtual function call". This message comes from a function called __purecall. What does it mean?

    C++ and C# both have the concept of a "pure virtual function" (which C# calls "abstract"). This is a method which is declared by the base class, but for which no implementation is provided. In C++ the syntax for this is "=0":

    class Base {
      Base() { f(); }
      virtual void f() = 0;

    If you attempt to create a Derived object, the base class will attempt to call Base::f, which does not exist since it is a pure virtual function. When this happens, the "pure virtual function call" error is raised and the program is terminated.

    Of course, the mistake is rarely as obvious as this. Typically, the call to the pure virtual function occurs deep inside the call stack of the constructor.

    This raises the side issue of the "novtable" optimization. As we noted above, the identity of the object changes during construction. This change of identity is performed by swapping the vtables around during construction. If you have a base class that is never instantiated directly but always via a derived class, and if you have followed the rules against calling virtual methods during construction, then you can use the novtable optimization to get rid of the vtable swapping during construction of the base class.

    If you use this optimization, then calling virtual methods during the base class's constructor or destructor will result in undefined behavior. It's a nice optimization, but it's your own responsibility to make sure you conform to its requirements.

    Sidebar: Why does C# not do type morphing during construction? One reason is that it would result in the possibility, given two objects A and B, that typeof(A) == typeof(B) yet sizeof(A) != sizeof(B). This would happen if A were a fully constructed object and B were a partially-constructed object on its way to becoming a derived object.

    Why is this so bad? Because the garbage collector is really keen on knowing the size of each object so it can know how much memory to free. It does this by checking the object's type. If an object's type did not completely determine its size, this would result in the garbage collector having to do extra work to figure out exactly how big the object is, which means extra code in the constructor and destructor, as well as space in the object, to keep track of which stage of construction/destruction is currently in progress. And all this for something most coding guidelines recommend against anyway.

Page 401 of 436 (4,356 items) «399400401402403»