Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(260)

Issue 107100043: re2: Remove comparisons of this with NULL.

Can't Edit
Can't Publish+Mail
Start Review
Created:
10 years, 6 months ago by thakis
Modified:
10 years, 6 months ago
Reviewers:
rsc
CC:
rsc, re2-dev_googlegroups.com
Visibility:
Public.

Description

Remove comparisons of this with NULL. Calling functions on objects that are NULL is undefined behavior. Hence, new versions of clang assume that `this` is never NULL, warn on comparisons of `this` with NULL, and optimize the comparison away. There were three comparisons of `this` with NULL in re2: 1. CharClass::Delete(). There are only two callers of this method, and as far as I can tell `this` can't be NULL there, so just delete that check. 2. Prefilter::DebugString(). This too has two callers: Prefilter::Info::ToString(), which already checks for NULL before calling, and DebugString() itself. Since several places check Prefilters for NULL, add explicit checks before calling here. 3. Prefilter::Info::ToString(). This has three callers. In 2 cases this can't be NULL. In the third case it could conceivably be NULL if op() is kRegexpConcat and nchild_args is 0, so add an explicit check here. Fixes https://code.google.com/p/re2/issues/detail?id=115

Patch Set 1 #

Unified diffs Side-by-side diffs Delta from patch set Stats (+5 lines, -16 lines) Patch
M re2/prefilter.cc View 5 chunks +5 lines, -14 lines 0 comments Download
M re2/regexp.cc View 1 chunk +0 lines, -2 lines 0 comments Download

Messages

Total messages: 5
thakis
`make test` is happy. Someone of the tests I added might not be necessary.
10 years, 6 months ago (2014-06-13 23:36:52 UTC) #1
thakis
Ping?
10 years, 6 months ago (2014-06-23 15:57:05 UTC) #2
rsc
I guess this is correct but it's really annoying.
10 years, 6 months ago (2014-06-26 15:03:11 UTC) #3
rsc
LGTM
10 years, 6 months ago (2014-06-26 15:03:38 UTC) #4
rsc
10 years, 6 months ago (2014-06-26 15:20:37 UTC) #5
*** Submitted as https://code.google.com/p/re2/source/detail?r=b92ce81f1e25 ***

Remove comparisons of this with NULL.

Calling functions on objects that are NULL is undefined behavior.
Hence, new versions of clang assume that `this` is never NULL,
warn on comparisons of `this` with NULL, and optimize the comparison away.

There were three comparisons of `this` with NULL in re2:

1. CharClass::Delete(). There are only two callers of this method, and
   as far as I can tell `this` can't be NULL there, so just delete that check.
2. Prefilter::DebugString(). This too has two callers:
Prefilter::Info::ToString(),
   which already checks for NULL before calling, and DebugString() itself.
   Since several places check Prefilters for NULL, add explicit checks before
   calling here.
3. Prefilter::Info::ToString(). This has three callers. In 2 cases this can't be
   NULL. In the third case it could conceivably be NULL if op() is
   kRegexpConcat and nchild_args is 0, so add an explicit check here.

Fixes https://code.google.com/p/re2/issues/detail?id=115

LGTM=rsc
R=rsc
CC=re2-dev
https://codereview.appspot.com/107100043

Committer: Russ Cox <rsc@swtch.com>
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b