summaryrefslogtreecommitdiffstats
path: root/intl/uconv/nsScriptableUConv.cpp
diff options
context:
space:
mode:
authorjanekptacijarabaci <janekptacijarabaci@seznam.cz>2018-04-25 15:48:44 +0200
committerjanekptacijarabaci <janekptacijarabaci@seznam.cz>2018-04-25 15:48:44 +0200
commit3ab6c7feee8126bdfc5c9ab9371db41102e12e95 (patch)
treea309c45826300b888238b6a517051fe7e71d63eb /intl/uconv/nsScriptableUConv.cpp
parentb18a9cf86ea25bc52d9cfea584e3aa8bfbe81f0a (diff)
parentb069dabc91b7e0f5f8d161cdbe598276a21d6d68 (diff)
downloadUXP-3ab6c7feee8126bdfc5c9ab9371db41102e12e95.tar
UXP-3ab6c7feee8126bdfc5c9ab9371db41102e12e95.tar.gz
UXP-3ab6c7feee8126bdfc5c9ab9371db41102e12e95.tar.lz
UXP-3ab6c7feee8126bdfc5c9ab9371db41102e12e95.tar.xz
UXP-3ab6c7feee8126bdfc5c9ab9371db41102e12e95.zip
Merge branch 'master' of https://github.com/MoonchildProductions/UXP into pm_url_1
Diffstat (limited to 'intl/uconv/nsScriptableUConv.cpp')
-rw-r--r--intl/uconv/nsScriptableUConv.cpp16
1 files changed, 14 insertions, 2 deletions
diff --git a/intl/uconv/nsScriptableUConv.cpp b/intl/uconv/nsScriptableUConv.cpp
index 7d4e932e2..43889ffa2 100644
--- a/intl/uconv/nsScriptableUConv.cpp
+++ b/intl/uconv/nsScriptableUConv.cpp
@@ -11,6 +11,7 @@
#include "nsIUnicodeDecoder.h"
#include "nsIUnicodeEncoder.h"
#include "mozilla/dom/EncodingUtils.h"
+#include "mozilla/CheckedInt.h"
using mozilla::dom::EncodingUtils;
@@ -39,7 +40,12 @@ nsScriptableUnicodeConverter::ConvertFromUnicodeWithLength(const nsAString& aSrc
const nsAFlatString& flatSrc = PromiseFlatString(aSrc);
rv = mEncoder->GetMaxLength(flatSrc.get(), inLength, aOutLen);
if (NS_SUCCEEDED(rv)) {
- *_retval = (char*)malloc(*aOutLen+1);
+ mozilla::CheckedInt<int32_t> needed(*aOutLen);
+ needed += 1;
+ if (!needed.isValid()) {
+ return NS_ERROR_OUT_OF_MEMORY;
+ }
+ *_retval = (char*)malloc(needed.value());
if (!*_retval)
return NS_ERROR_OUT_OF_MEMORY;
@@ -145,7 +151,13 @@ nsScriptableUnicodeConverter::ConvertFromByteArray(const uint8_t* aData,
inLength, &outLength);
if (NS_SUCCEEDED(rv))
{
- char16_t* buf = (char16_t*)malloc((outLength+1) * sizeof(char16_t));
+ mozilla::CheckedInt<nsACString::size_type> needed(outLength);
+ needed += 1;
+ needed *= sizeof(char16_t);
+ if (!needed.isValid()) {
+ return NS_ERROR_OUT_OF_MEMORY;
+ }
+ char16_t* buf = (char16_t*)malloc(needed.value());
if (!buf)
return NS_ERROR_OUT_OF_MEMORY;