Skip to content

Commit

Permalink
Bug 1393235 - Fix improper usages of string functions. r=njn
Browse files Browse the repository at this point in the history
This fixes usages of `Find`, `RFind` and the equality operator that kind of
work right now but will break with the proper type checking of a templatized
version of the string classes.

For `Find` and `RFind` it appears that `nsCString::(R)Find("foo", 0)` calls
were being coerced to the `Find(char*, bool, int, int)` versions. The intent was
probably to just start searching from position zero.

For the equality operator, the type of nullptr is nullptr_t rather than
char(16_t)* so we'd need to add an operator overload that takes nullptr_t. In
this case just using `IsVoid` is probably more appropriate.

--HG--
extra : rebase_source : 50f78519084012ca669da0a211c489520c11d6b6
  • Loading branch information
EricRahm authored and Alex Kontos committed Aug 16, 2019
1 parent 988be16 commit 7ded5ff
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion docshell/base/nsDefaultURIFixup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,7 @@ nsDefaultURIFixup::FixupURIProtocol(const nsACString& aURIString,
// no-scheme.com/query?foo=http://www.foo.com
// user:[email protected]
//
int32_t schemeDelim = uriString.Find("://", 0);
int32_t schemeDelim = uriString.Find("://");
int32_t firstDelim = uriString.FindCharInSet("/:");
if (schemeDelim <= 0 ||
(firstDelim != -1 && schemeDelim > firstDelim)) {
Expand Down
2 changes: 1 addition & 1 deletion dom/media/gmp/ChromiumCDMChild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ ChromiumCDMChild::OnResolveNewSessionPromiseInternal(uint32_t aPromiseId,
// a session it calls OnResolveNewSessionPromise with nullptr as the sessionId.
// We can safely assume this means that we have failed to load a session
// as the other methods specify calling 'OnRejectPromise' when they fail.
bool loadSuccessful = aSessionId != nullptr;
bool loadSuccessful = !aSessionId.IsEmpty();
GMP_LOG("ChromiumCDMChild::OnResolveNewSessionPromise(pid=%u, sid=%s) "
"resolving %s load session ",
aPromiseId,
Expand Down
2 changes: 1 addition & 1 deletion toolkit/components/places/nsNavHistory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1963,7 +1963,7 @@ PlacesSQLQueryBuilder::Where()

// If we used WHERE already, we inject the conditions
// in place of {ADDITIONAL_CONDITIONS}
if (mQueryString.Find("{ADDITIONAL_CONDITIONS}", 0) != kNotFound) {
if (mQueryString.Find("{ADDITIONAL_CONDITIONS}") != kNotFound) {
nsAutoCString innerCondition;
// If we have condition AND it
if (!mConditions.IsEmpty()) {
Expand Down
4 changes: 2 additions & 2 deletions toolkit/components/url-classifier/Classifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -989,7 +989,7 @@ Classifier::ScanStoreDir(nsIFile* aDirectory, nsTArray<nsCString>& aTables)
// Both v2 and v4 contain .pset file
nsCString suffix(NS_LITERAL_CSTRING(".pset"));

int32_t dot = leafName.RFind(suffix, 0);
int32_t dot = leafName.RFind(suffix);
if (dot != -1) {
leafName.Cut(dot, suffix.Length());
aTables.AppendElement(leafName);
Expand Down Expand Up @@ -1579,7 +1579,7 @@ Classifier::LoadMetadata(nsIFile* aDirectory, nsACString& aResult)
rv = file->GetNativeLeafName(tableName);
NS_ENSURE_SUCCESS(rv, rv);

int32_t dot = tableName.RFind(METADATA_SUFFIX, 0);
int32_t dot = tableName.RFind(METADATA_SUFFIX);
if (dot == -1) {
continue;
}
Expand Down

0 comments on commit 7ded5ff

Please sign in to comment.