Skip navigation

The VARIANT datatype is the worst, most error prone piece of shit i’ve ever seen.

look at this bug:


  for( int s = 0 ; s < count ; s++ )
  {
    _variant_t vi( s ) ;

    ADOField * field ;

    if( CHECK( fields->get_Item( vi, &field ), "Getting field item" ) )
    {
      BSTR name ;

      CHECK( field->get_Name( &name ), "getting name" ) ;

      wprintf( L"| %10s |", name );
    }

  }


Why did it crash? I’ll paste the correct non-crashing code below and see if you can find it



  for( short s = 0 ; s < count ; s++ )
  {
    _variant_t vi( s ) ;

    ADOField * field ;

    if( CHECK( fields->get_Item( vi, &field ), "Getting field item" ) )
    {
      BSTR name ;

      CHECK( field->get_Name( &name ), "getting name" ) ;

      wprintf( L"| %10s |", name );
    }

  }


See it? When I declared the counter variable s as an int, the variant type was the wrong type (it was an INT type instead of a SHORT type).

I only GUESSED this was the problem not from the amazing documentation that ms keeps on this, but from this article looking at how they browsed the thing.

I was shocked and amazed that the VARIANT type was ever in use by anyone at any point in time, and how EXTENSIVELY its used in ADO.

I mean, its an ugly type and this is a STUPID reason for a bug to exist.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: