Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1bf3b4a0 authored by Todd Poynor's avatar Todd Poynor
Browse files

String8: ensure static init done prior to empty string reference

Avoid NULL deref on static initialization of empty String8 objects prior
to libutils static init.

Change-Id: I3d420041ba62b97ed8c2dfd2532a2dcd72b84ff1
parent 77943437
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -48,12 +48,16 @@ int gDarwinIsReallyAnnoying;

static inline char* getEmptyString()
{
    if (!gEmptyStringBuf) initialize_string8();

    gEmptyStringBuf->acquire();
    return gEmptyString;
}

void initialize_string8()
{
    if (gEmptyStringBuf) return;

    // HACK: This dummy dependency forces linking libutils Static.cpp,
    // which is needed to initialize String8/String16 classes.
    // These variables are named for Darwin, but are needed elsewhere too,