Bug 1530564 - Fix truncation warnings in TestAUSHelper.cpp. r=mhowell
authorRobert Strong <robert.bugzilla@gmail.com>
Tue, 26 Feb 2019 18:29:18 +0000
changeset 519127 44b0b51ef2143bbb81d47d60fd3ed8a6451751ec
parent 519126 dfb53709e5fdb77ef09ff281309afb8eb845a83f
child 519128 87514c3aaa3a9bd26879cc7fdf5e3c96de948854
push id10862
push userffxbld-merge
push dateMon, 11 Mar 2019 13:01:11 +0000
treeherdermozilla-beta@a2e7f5c935da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmhowell
bugs1530564
milestone67.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1530564 - Fix truncation warnings in TestAUSHelper.cpp. r=mhowell Differential Revision: https://phabricator.services.mozilla.com/D21164
toolkit/mozapps/update/tests/TestAUSHelper.cpp
toolkit/mozapps/update/tests/moz.build
--- a/toolkit/mozapps/update/tests/TestAUSHelper.cpp
+++ b/toolkit/mozapps/update/tests/TestAUSHelper.cpp
@@ -80,46 +80,56 @@ int NS_main(int argc, NS_tchar **argv) {
     if (!NS_tstrcmp(argv[1], NS_T("post-update-async")) ||
         !NS_tstrcmp(argv[1], NS_T("post-update-sync"))) {
       NS_tchar exePath[MAXPATHLEN];
 #ifdef XP_WIN
       if (!::GetModuleFileNameW(0, exePath, MAXPATHLEN)) {
         return 1;
       }
 #else
-      NS_tsnprintf(exePath, sizeof(exePath) / sizeof(exePath[0]), NS_T("%s"),
-                   argv[0]);
+      if (!NS_tsnprintf(exePath, sizeof(exePath) / sizeof(exePath[0]),
+                        NS_T("%s"), argv[0])) {
+        return 1;
+      }
 #endif
       NS_tchar runFilePath[MAXPATHLEN];
-      NS_tsnprintf(runFilePath, sizeof(runFilePath) / sizeof(runFilePath[0]),
-                   NS_T("%s.running"), exePath);
+      if (!NS_tsnprintf(runFilePath,
+                        sizeof(runFilePath) / sizeof(runFilePath[0]),
+                        NS_T("%s.running"), exePath)) {
+        return 1;
+      }
 #ifdef XP_WIN
       if (!NS_taccess(runFilePath, F_OK)) {
         // This makes it possible to check if the post update process was
         // launched twice which happens when the service performs an update.
         NS_tchar runFilePathBak[MAXPATHLEN];
-        NS_tsnprintf(runFilePathBak,
-                     sizeof(runFilePathBak) / sizeof(runFilePathBak[0]),
-                     NS_T("%s.bak"), runFilePath);
+        if (!NS_tsnprintf(runFilePathBak,
+                          sizeof(runFilePathBak) / sizeof(runFilePathBak[0]),
+                          NS_T("%s.bak"), runFilePath)) {
+          return 1;
+        }
         MoveFileExW(runFilePath, runFilePathBak, MOVEFILE_REPLACE_EXISTING);
       }
 #endif
       WriteMsg(runFilePath, "running");
 
       if (!NS_tstrcmp(argv[1], NS_T("post-update-sync"))) {
 #ifdef XP_WIN
         Sleep(2000);
 #else
         sleep(2);
 #endif
       }
 
       NS_tchar logFilePath[MAXPATHLEN];
-      NS_tsnprintf(logFilePath, sizeof(logFilePath) / sizeof(logFilePath[0]),
-                   NS_T("%s.log"), exePath);
+      if (!NS_tsnprintf(logFilePath,
+                        sizeof(logFilePath) / sizeof(logFilePath[0]),
+                        NS_T("%s.log"), exePath)) {
+        return 1;
+      }
       WriteMsg(logFilePath, "post-update");
       return 0;
     }
   }
 
   if (argc < 3) {
     fprintf(
         stderr,
@@ -172,38 +182,46 @@ int NS_main(int argc, NS_tchar **argv) {
     // Not implemented on non-Windows platforms
     return 1;
 #endif
   }
 
   if (!NS_tstrcmp(argv[1], NS_T("setup-symlink"))) {
 #ifdef XP_UNIX
     NS_tchar path[MAXPATHLEN];
-    NS_tsnprintf(path, sizeof(path) / sizeof(path[0]), NS_T("%s/%s"),
-                 NS_T("/tmp"), argv[2]);
+    if (!NS_tsnprintf(path, sizeof(path) / sizeof(path[0]), NS_T("%s/%s"),
+                      NS_T("/tmp"), argv[2])) {
+      return 1;
+    }
     if (mkdir(path, 0755)) {
       return 1;
     }
-    NS_tsnprintf(path, sizeof(path) / sizeof(path[0]), NS_T("%s/%s/%s"),
-                 NS_T("/tmp"), argv[2], argv[3]);
+    if (!NS_tsnprintf(path, sizeof(path) / sizeof(path[0]), NS_T("%s/%s/%s"),
+                      NS_T("/tmp"), argv[2], argv[3])) {
+      return 1;
+    }
     if (mkdir(path, 0755)) {
       return 1;
     }
-    NS_tsnprintf(path, sizeof(path) / sizeof(path[0]), NS_T("%s/%s/%s/%s"),
-                 NS_T("/tmp"), argv[2], argv[3], argv[4]);
+    if (!NS_tsnprintf(path, sizeof(path) / sizeof(path[0]), NS_T("%s/%s/%s/%s"),
+                      NS_T("/tmp"), argv[2], argv[3], argv[4])) {
+      return 1;
+    }
     FILE *file = NS_tfopen(path, NS_T("w"));
     if (file) {
       fputs(NS_T("test"), file);
       fclose(file);
     }
     if (symlink(path, argv[5]) != 0) {
       return 1;
     }
-    NS_tsnprintf(path, sizeof(path) / sizeof(path[0]), NS_T("%s/%s"),
-                 NS_T("/tmp"), argv[2]);
+    if (!NS_tsnprintf(path, sizeof(path) / sizeof(path[0]), NS_T("%s/%s"),
+                      NS_T("/tmp"), argv[2])) {
+      return 1;
+    }
     if (argc > 6 && !NS_tstrcmp(argv[6], NS_T("change-perm"))) {
       if (chmod(path, 0644)) {
         return 1;
       }
     }
     return 0;
 #else
     // Not implemented on non-Unix platforms
@@ -213,33 +231,41 @@ int NS_main(int argc, NS_tchar **argv) {
 
   if (!NS_tstrcmp(argv[1], NS_T("remove-symlink"))) {
 #ifdef XP_UNIX
     // The following can be called at the start of a test in case these symlinks
     // need to be removed if they already exist and at the end of a test to
     // remove the symlinks created by the test so ignore file doesn't exist
     // errors.
     NS_tchar path[MAXPATHLEN];
-    NS_tsnprintf(path, sizeof(path) / sizeof(path[0]), NS_T("%s/%s"),
-                 NS_T("/tmp"), argv[2]);
+    if (!NS_tsnprintf(path, sizeof(path) / sizeof(path[0]), NS_T("%s/%s"),
+                      NS_T("/tmp"), argv[2])) {
+      return 1;
+    }
     if (chmod(path, 0755) && errno != ENOENT) {
       return 1;
     }
-    NS_tsnprintf(path, sizeof(path) / sizeof(path[0]), NS_T("%s/%s/%s/%s"),
-                 NS_T("/tmp"), argv[2], argv[3], argv[4]);
+    if (!NS_tsnprintf(path, sizeof(path) / sizeof(path[0]), NS_T("%s/%s/%s/%s"),
+                      NS_T("/tmp"), argv[2], argv[3], argv[4])) {
+      return 1;
+    }
     if (unlink(path) && errno != ENOENT) {
       return 1;
     }
-    NS_tsnprintf(path, sizeof(path) / sizeof(path[0]), NS_T("%s/%s/%s"),
-                 NS_T("/tmp"), argv[2], argv[3]);
+    if (!NS_tsnprintf(path, sizeof(path) / sizeof(path[0]), NS_T("%s/%s/%s"),
+                      NS_T("/tmp"), argv[2], argv[3])) {
+      return 1;
+    }
     if (rmdir(path) && errno != ENOENT) {
       return 1;
     }
-    NS_tsnprintf(path, sizeof(path) / sizeof(path[0]), NS_T("%s/%s"),
-                 NS_T("/tmp"), argv[2]);
+    if (!NS_tsnprintf(path, sizeof(path) / sizeof(path[0]), NS_T("%s/%s"),
+                      NS_T("/tmp"), argv[2])) {
+      return 1;
+    }
     if (rmdir(path) && errno != ENOENT) {
       return 1;
     }
     return 0;
 #else
     // Not implemented on non-Unix platforms
     return 1;
 #endif
@@ -340,21 +366,25 @@ int NS_main(int argc, NS_tchar **argv) {
   }
 
   // File in use test helper section
   if (!NS_tstrcmp(argv[4], NS_T("-s"))) {
     // Note: glibc's getcwd() allocates the buffer dynamically using malloc(3)
     // if buf (the 1st param) is NULL so free cwd when it is no longer needed.
     NS_tchar *cwd = NS_tgetcwd(nullptr, 0);
     NS_tchar inFilePath[MAXPATHLEN];
-    NS_tsnprintf(inFilePath, sizeof(inFilePath) / sizeof(inFilePath[0]),
-                 NS_T("%s/%s"), cwd, argv[2]);
+    if (!NS_tsnprintf(inFilePath, sizeof(inFilePath) / sizeof(inFilePath[0]),
+                      NS_T("%s/%s"), cwd, argv[2])) {
+      return 1;
+    }
     NS_tchar outFilePath[MAXPATHLEN];
-    NS_tsnprintf(outFilePath, sizeof(outFilePath) / sizeof(outFilePath[0]),
-                 NS_T("%s/%s"), cwd, argv[3]);
+    if (!NS_tsnprintf(outFilePath, sizeof(outFilePath) / sizeof(outFilePath[0]),
+                      NS_T("%s/%s"), cwd, argv[3])) {
+      return 1;
+    }
     free(cwd);
 
     int seconds = NS_ttoi(argv[5]);
 #ifdef XP_WIN
     HANDLE hFile = INVALID_HANDLE_VALUE;
     if (argc == 7) {
       hFile = CreateFileW(argv[6], DELETE | GENERIC_WRITE, 0, nullptr,
                           OPEN_EXISTING, 0, nullptr);
@@ -382,18 +412,20 @@ int NS_main(int argc, NS_tchar **argv) {
 #endif
     WriteMsg(outFilePath, "finished");
     return 0;
   }
 
   {
     // Command line argument test helper section
     NS_tchar logFilePath[MAXPATHLEN];
-    NS_tsnprintf(logFilePath, sizeof(logFilePath) / sizeof(logFilePath[0]),
-                 NS_T("%s"), argv[2]);
+    if (!NS_tsnprintf(logFilePath, sizeof(logFilePath) / sizeof(logFilePath[0]),
+                      NS_T("%s"), argv[2])) {
+      return 1;
+    }
 
     FILE *logFP = NS_tfopen(logFilePath, NS_T("wb"));
     if (!logFP) {
       return 1;
     }
     for (int i = 1; i < argc; ++i) {
       fprintf(logFP, LOG_S "\n", argv[i]);
     }
--- a/toolkit/mozapps/update/tests/moz.build
+++ b/toolkit/mozapps/update/tests/moz.build
@@ -102,12 +102,8 @@ FINAL_TARGET_FILES += [
 ]
 
 FINAL_TARGET_PP_FILES += [
     'data/xpcshellConstantsPP.js',
 ]
 
 with Files("browser/browser_TelemetryUpdatePing.js"):
     BUG_COMPONENT = ("Toolkit", "Telemetry")
-
-if CONFIG['CC_TYPE'] == 'gcc':
-    CXXFLAGS += ['-Wno-format-truncation']
-