New issue
Advanced search Search tips

Issue 810088 link

Starred by 1 user

Issue metadata

Status: Fixed
Owner:
Closed: Feb 2018
EstimatedDays: ----
NextAction: ----
OS: ----
Pri: 3
Type: Bug



Sign in to add a comment

Don't use memset when the intent is to value construct

Project Member Reported by cblume@chromium.org, Feb 7 2018

Issue description

In C, using memset(0) is normal/common for initialization.
But in C++, typically we want value initialization. The constructor knows how to initialize that class.

This is because in C it is more common for value initialization to effectively set everything to 0.

A problem came up where a class was being initialized with memset(0) but that class had a base::Optional member with negative logic. storage_.is_null = true would indicate the optional had not been filled. memset(0) set it to false, which incorrectly indicated a filled optional.

base::Optional was updated to use affirmative storage_.is_populated_ rather than negative storage_.is_null_, which allowed memset(0) to work. But the correct solution is to stop using memset(0).
 
Project Member

Comment 1 by bugdroid1@chromium.org, Feb 7 2018

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/b26ba87795b76e5fb546817630e19486bd0ccdfb

commit b26ba87795b76e5fb546817630e19486bd0ccdfb
Author: Chris Blume <cblume@chromium.org>
Date: Wed Feb 07 22:06:59 2018

Don't use memset(0) for value initialization

memset(0) is a common way to value initialze in C because in C it is
very common for 0 bits to represet a value-initialized state. In C++
this is still common, but less so. But C++ also provides a way to
explicitly value initialize.

Rely on value initialization instead of memset(0) when the intent isn't
"set these bits to zero".

BUG= 810088 

Change-Id: I5736f072b101df846de9c2db15b29230a0efb3fb
Reviewed-on: https://chromium-review.googlesource.com/907290
Reviewed-by: Sadrul Chowdhury <sadrul@chromium.org>
Commit-Queue: Chris Blume <cblume@chromium.org>
Cr-Commit-Position: refs/heads/master@{#535159}
[modify] https://crrev.com/b26ba87795b76e5fb546817630e19486bd0ccdfb/content/browser/web_contents/aura/overscroll_navigation_overlay_unittest.cc

Status: Fixed (was: Started)

Sign in to add a comment