BUG OF THE MONTH | Using memset to clear memory

static void freeMetaUI(gpointer p)
  MakeMetaUI* ui = p;
  memset(ui, ~0, sizeof(MakeMetaUI));

Warning V597 The compiler could delete the ‘memset’ function call, which is used to flush ‘ui’ object. The memset_s() function should be used to erase the private data. makemeta-ui.c:53

The most frequent mistake is to use the memset function to clear memory. In short, the compiler has every right to delete memset calls if it considers them meaningless. It usually happens when the buffer is cleared in the end of an operation and is no longer used. 

Please click here to see more bugs from this project.

Leave a Reply

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

You are commenting using your 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 )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.