Bug 1382910 - Consistently treat empty env var values the same as the env var not being set. r?njn draft
authorMarkus Stange <mstange@themasta.com>
Thu, 20 Jul 2017 20:52:20 -0400
changeset 614590 508f22f3910a16d81f01ca454908550104801812
parent 614589 b705c0f10ab6929ed2fe5362fc7432e8fbe7f26e
child 614591 5e5dcbde6569ad90863b3bc4d8b55100b9040047
child 614734 6e02c8969b98be9dcf3e0e3b601b782bcd9c5118
push id70072
push userbmo:mstange@themasta.com
push dateMon, 24 Jul 2017 21:00:07 +0000
reviewersnjn
bugs1382910
milestone56.0a1
Bug 1382910 - Consistently treat empty env var values the same as the env var not being set. r?njn This is what prenv.h suggests: When manipulating the environment there is no way to un-set an environment variable across all platforms. We suggest you interpret the return of a pointer to null-string to mean the same as a return of NULL from PR_GetEnv(). I interpret "null-string" to mean "empty string". MozReview-Commit-ID: 2mfVD1zULXL
tools/profiler/core/platform.cpp
--- a/tools/profiler/core/platform.cpp
+++ b/tools/profiler/core/platform.cpp
@@ -2191,70 +2191,71 @@ profiler_init(void* aStackTop)
     RegisterProfilerLabelEnterExit(MozGlueLabelEnter, MozGlueLabelExit);
 
     // (Linux-only) We could create CorePS::mLul and read unwind info into it
     // at this point. That would match the lifetime implied by destruction of
     // it in profiler_shutdown() just below. However, that gives a big delay on
     // startup, even if no profiling is actually to be done. So, instead, it is
     // created on demand at the first call to PlatformStart().
 
-    if (!getenv("MOZ_PROFILER_STARTUP")) {
+    const char* startupEnv = getenv("MOZ_PROFILER_STARTUP");
+    if (!startupEnv || startupEnv[0] == '\0') {
       return;
     }
 
     LOG("- MOZ_PROFILER_STARTUP is set");
 
     const char* startupEntries = getenv("MOZ_PROFILER_STARTUP_ENTRIES");
-    if (startupEntries) {
+    if (startupEntries && startupEntries[0] != '\0') {
       errno = 0;
       entries = strtol(startupEntries, nullptr, 10);
       if (errno == 0 && entries > 0) {
         LOG("- MOZ_PROFILER_STARTUP_ENTRIES = %d", entries);
       } else {
         PrintUsageThenExit(1);
       }
     }
 
     const char* startupInterval = getenv("MOZ_PROFILER_STARTUP_INTERVAL");
-    if (startupInterval) {
+    if (startupInterval && startupInterval[0] != '\0') {
       errno = 0;
       interval = PR_strtod(startupInterval, nullptr);
       if (errno == 0 && interval > 0.0 && interval <= 1000.0) {
         LOG("- MOZ_PROFILER_STARTUP_INTERVAL = %f", interval);
       } else {
         PrintUsageThenExit(1);
       }
     }
 
     const char* startupFeaturesBitfield =
       getenv("MOZ_PROFILER_STARTUP_FEATURES_BITFIELD");
-    if (startupFeaturesBitfield) {
+    if (startupFeaturesBitfield && startupFeaturesBitfield[0] != '\0') {
       errno = 0;
       features = strtol(startupFeaturesBitfield, nullptr, 10);
       if (errno == 0 && features != 0) {
         LOG("- MOZ_PROFILER_STARTUP_FEATURES_BITFIELD = %d", features);
       } else {
         PrintUsageThenExit(1);
       }
     } else {
       const char* startupFeatures = getenv("MOZ_PROFILER_STARTUP_FEATURES");
-      if (startupFeatures) {
+      if (startupFeatures && startupFeatures[0] != '\0') {
         // Interpret startupFeatures as a list of feature strings, separated by
         // commas.
         UniquePtr<char[]> featureStringStorage;
         nsTArray<const char*> featureStringArray =
           SplitAtCommas(startupFeatures, featureStringStorage);
         features = ParseFeaturesFromStringArray(featureStringArray.Elements(),
                                                 featureStringArray.Length());
         LOG("- MOZ_PROFILER_STARTUP_FEATURES = %d", features);
       }
     }
 
     const char* startupFilters = getenv("MOZ_PROFILER_STARTUP_FILTERS");
-    if (startupFilters) {
+    if (startupFilters && startupFilters[0] != '\0') {
       filters = SplitAtCommas(startupFilters, filterStorage);
       LOG("- MOZ_PROFILER_STARTUP_FILTERS = %s", startupFilters);
     }
 
     locked_profiler_start(lock, entries, interval, features,
                           filters.Elements(), filters.Length());
   }