Peeter Joot's (OLD) Blog.

Math, physics, perl, and programming obscurity.

A new creative way to mess up a memset call.

Posted by peeterjoot on June 8, 2010

Here’s a way to mess up a memset call that impressed me with it’s creative uniqueness:

STRU_UD   ud[MAX_ATTACHMENTS] ;

memset( &ud, 0x00, sizeof( ud[MAX_ATTACHMENTS] ) ) ;

What was really meant was:

memset( &ud, 0x00, sizeof( ud ) ) ;

(ie: the whole array, which has MAX_ATTACHMENTS elements). Instead the person who coded this, ended up only initializing the first element, since they asked to initialize just the size of the last element in the array.

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: