Bug 1424120 - Part 5: Enforce support for only radix of 10 and 16. r=njn
authorEric Rahm <erahm@mozilla.com>
Thu, 07 Dec 2017 18:54:13 -0800
changeset 448697 2423de2699b16ffd269fc463e4e2515c0d26d101
parent 448696 b24d0d0ff3c81f0c3e7f9b013440a35f6ed20e55
child 448698 111b8a7cde41485e708205475db0fdb4434c7e8e
push id8527
push userCallek@gmail.com
push dateThu, 11 Jan 2018 21:05:50 +0000
treeherdermozilla-beta@95342d212a7a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnjn
bugs1424120
milestone59.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 1424120 - Part 5: Enforce support for only radix of 10 and 16. r=njn In theory other radixes can be passed in but we don't actually handle them. This asserts that the radix is supported and just switches over to using 10 and 16 directly.
accessible/xul/XULMenuAccessible.cpp
xpcom/string/nsString.h
xpcom/string/nsTString.h
xpcom/string/nsTStringObsolete.cpp
--- a/accessible/xul/XULMenuAccessible.cpp
+++ b/accessible/xul/XULMenuAccessible.cpp
@@ -209,19 +209,19 @@ XULMenuitemAccessible::KeyboardShortcut(
   uint32_t key = 0;
 
   nsAutoString keyStr;
   keyElm->GetAttr(kNameSpaceID_None, nsGkAtoms::key, keyStr);
   if (keyStr.IsEmpty()) {
     nsAutoString keyCodeStr;
     keyElm->GetAttr(kNameSpaceID_None, nsGkAtoms::keycode, keyCodeStr);
     nsresult errorCode;
-    key = keyStr.ToInteger(&errorCode, kRadix10);
+    key = keyStr.ToInteger(&errorCode, /* aRadix = */ 10);
     if (NS_FAILED(errorCode)) {
-      key = keyStr.ToInteger(&errorCode, kRadix16);
+      key = keyStr.ToInteger(&errorCode, /* aRadix = */ 16);
     }
   } else {
     key = keyStr[0];
   }
 
   nsAutoString modifiersStr;
   keyElm->GetAttr(kNameSpaceID_None, nsGkAtoms::modifiers, modifiersStr);
 
--- a/xpcom/string/nsString.h
+++ b/xpcom/string/nsString.h
@@ -15,22 +15,16 @@
 #include "nsDependentSubstring.h"
 #include "nsReadableUtils.h"
 
 // enable support for the obsolete string API if not explicitly disabled
 #ifndef MOZ_STRING_WITH_OBSOLETE_API
 #define MOZ_STRING_WITH_OBSOLETE_API 1
 #endif
 
-#if MOZ_STRING_WITH_OBSOLETE_API
-// radix values for ToInteger/AppendInt
-#define kRadix10        (10)
-#define kRadix16        (16)
-#endif
-
 #include "nsTString.h"
 
 static_assert(sizeof(char16_t) == 2, "size of char16_t must be 2");
 static_assert(sizeof(nsString::char_type) == 2,
               "size of nsString::char_type must be 2");
 static_assert(nsString::char_type(-1) > nsString::char_type(0),
               "nsString::char_type must be unsigned");
 static_assert(sizeof(nsCString::char_type) == 1,
--- a/xpcom/string/nsTString.h
+++ b/xpcom/string/nsTString.h
@@ -377,25 +377,25 @@ public:
   float ToFloat(nsresult* aErrorCode) const;
 
   /**
    * Perform string to int conversion.
    * @param   aErrorCode will contain error if one occurs
    * @param   aRadix is the radix to use. Only 10 and 16 are supported.
    * @return  int rep of string value, and possible (out) error code
    */
-  int32_t ToInteger(nsresult* aErrorCode, uint32_t aRadix = kRadix10) const;
+  int32_t ToInteger(nsresult* aErrorCode, uint32_t aRadix = 10) const;
 
   /**
    * Perform string to 64-bit int conversion.
    * @param   aErrorCode will contain error if one occurs
    * @param   aRadix is the radix to use. Only 10 and 16 are supported.
    * @return  64-bit int rep of string value, and possible (out) error code
    */
-  int64_t ToInteger64(nsresult* aErrorCode, uint32_t aRadix = kRadix10) const;
+  int64_t ToInteger64(nsresult* aErrorCode, uint32_t aRadix = 10) const;
 
 
   /**
    * |Left|, |Mid|, and |Right| are annoying signatures that seem better almost
    * any _other_ way than they are now.  Consider these alternatives
    *
    * aWritable = aReadable.Left(17);   // ...a member function that returns a |Substring|
    * aWritable = Left(aReadable, 17);  // ...a global function that returns a |Substring|
--- a/xpcom/string/nsTStringObsolete.cpp
+++ b/xpcom/string/nsTStringObsolete.cpp
@@ -112,16 +112,18 @@ nsTString<T>::RFindCharInSet(const char_
 
 
 // Common logic for nsTString<T>::ToIntger and nsTString<T>::ToInteger64.
 template <typename T, typename int_type>
 int_type
 ToIntegerCommon(const nsTString<T>& aSrc,
                 nsresult* aErrorCode, uint32_t aRadix)
 {
+  MOZ_ASSERT(aRadix == 10 || aRadix == 16);
+
   using char_type = typename nsTString<T>::char_type;
 
   auto cp = aSrc.BeginReading();
   mozilla::CheckedInt<int_type> result;
   bool negate = false;
   char_type theChar = 0;
 
   //initial value, override if we find an integer