コード例 #1
0
ファイル: nsTArray.cpp プロジェクト: isleon/Jaxer
PRBool
nsTArray_base::EnsureCapacity(size_type capacity, size_type elemSize) {
  // This should be the most common case so test this first
  if (capacity <= mHdr->mCapacity)
    return PR_TRUE;

  // If the requested memory allocation exceeds size_type(-1)/2, then our
  // doubling algorithm may not be able to allocate it.  Additionally we
  // couldn't fit in the Header::mCapacity member. Just bail out in cases
  // like that.  We don't want to be allocating 2 GB+ arrays anyway.
  if (capacity * elemSize > size_type(-1)/2) {
    NS_ERROR("Attempting to allocate excessively large array");
    return PR_FALSE;
  }

  if (mHdr == &sEmptyHdr) {
    // NS_Alloc new data
    Header *header = static_cast<Header*>
                                (NS_Alloc(sizeof(Header) + capacity * elemSize));
    if (!header)
      return PR_FALSE;
    header->mLength = 0;
    header->mCapacity = capacity;
    header->mIsAutoArray = 0;
    mHdr = header;
    
    return PR_TRUE;
  }

  // Use doubling algorithm when forced to increase available capacity.
  capacity = PR_MAX(capacity, mHdr->mCapacity << 1);

  Header *header;
  if (UsesAutoArrayBuffer()) {
    // NS_Alloc and copy
    header = static_cast<Header*>
                        (NS_Alloc(sizeof(Header) + capacity * elemSize));
    if (!header)
      return PR_FALSE;

    memcpy(header, mHdr, sizeof(Header) + Length() * elemSize);
  } else {
    // NS_Realloc existing data
    size_type size = sizeof(Header) + capacity * elemSize;
    header = static_cast<Header*>(NS_Realloc(mHdr, size));
    if (!header)
      return PR_FALSE;
  }

  header->mCapacity = capacity;
  mHdr = header;

  return PR_TRUE;
}
コード例 #2
0
ファイル: nsWildCard.cpp プロジェクト: abhishekvp/gecko-dev
static int
ns_WildCardMatch(const T *str, const T *xp, bool case_insensitive)
{
    T *expr = nullptr;
    int x, ret = MATCH;

    if (!nsCharTraits<T>::find(xp, nsCharTraits<T>::length(xp), T('~')))
        return ::_shexp_match(str, xp, case_insensitive, 0);

    expr = (T *) NS_Alloc((nsCharTraits<T>::length(xp) + 1) * sizeof(T));
    if(!expr)
        return NOMATCH;
    memcpy(expr, xp, (nsCharTraits<T>::length(xp) + 1) * sizeof(T));

    x = ::_scan_and_copy(expr, T('~'), T('\0'), static_cast<T*>(nullptr));
    if (x != ABORTED && expr[x] == '~') {
        expr[x++] = '\0';
        ret = ::_shexp_match(str, &expr[x], case_insensitive, 0);
        switch (ret) {
        case NOMATCH: ret = MATCH;   break;
        case MATCH:   ret = NOMATCH; break;
        default:                     break;
        }
    }
    if (ret == MATCH)
        ret = ::_shexp_match(str, expr, case_insensitive, 0);

    NS_Free(expr);
    return ret;
}
コード例 #3
0
/* void GetDictionaryList ([array, size_is (count)] out wstring dictionaries, out PRUint32 count); */
NS_IMETHODIMP mozHunspell::GetDictionaryList(PRUnichar ***aDictionaries,
                                            PRUint32 *aCount)
{
  if (!aDictionaries || !aCount)
    return NS_ERROR_NULL_POINTER;

  AppendNewStruct ans = {
    (PRUnichar**) NS_Alloc(sizeof(PRUnichar*) * mDictionaries.Count()),
    0,
    PR_FALSE
  };

  // This pointer is used during enumeration
  mDictionaries.EnumerateRead(AppendNewString, &ans);

  if (ans.failed) {
    while (ans.count) {
      --ans.count;
      NS_Free(ans.dics[ans.count]);
    }
    NS_Free(ans.dics);
    return NS_ERROR_OUT_OF_MEMORY;
  }

  *aDictionaries = ans.dics;
  *aCount = ans.count;

  return NS_OK;
}
コード例 #4
0
// Caller is responsible for freeing returned buffer.
static char* CFStringRefToUTF8Buffer(CFStringRef cfString)
{
  const char* buffer = ::CFStringGetCStringPtr(cfString, kCFStringEncodingUTF8);
  if (buffer) {
    return PL_strdup(buffer);
  }

  int bufferLength =
    ::CFStringGetMaximumSizeForEncoding(::CFStringGetLength(cfString),
                                        kCFStringEncodingUTF8) + 1;
  char* newBuffer = static_cast<char*>(NS_Alloc(bufferLength));
  if (!newBuffer) {
    return nullptr;
  }

  if (!::CFStringGetCString(cfString, newBuffer, bufferLength,
                            kCFStringEncodingUTF8)) {
    NS_Free(newBuffer);
    return nullptr;
  }

  newBuffer = static_cast<char*>(NS_Realloc(newBuffer,
                                            PL_strlen(newBuffer) + 1));
  return newBuffer;
}
コード例 #5
0
nsresult
sbSecurityMixin::CopyIIDArray(PRUint32 aCount, const nsIID **aSourceArray, nsIID ***aDestArray)
{
    NS_ENSURE_ARG_POINTER(aSourceArray);
    NS_ENSURE_ARG_POINTER(aDestArray);

    *aDestArray = 0;

    nsIID **iids = static_cast<nsIID**>( NS_Alloc( aCount * sizeof(nsIID*) ) );
    if (!iids) {
        return NS_ERROR_OUT_OF_MEMORY;
    }

    for (PRUint32 index = 0; index < aCount; ++index) {
        iids[index] = static_cast<nsIID*>( SB_CloneMemory( aSourceArray[index], sizeof(nsIID) ) );

        if (!iids[index]) {
            for (PRUint32 alloc_index = 0; alloc_index < index; ++alloc_index)
                NS_Free( iids[alloc_index] );
            NS_Free(iids);
            return NS_ERROR_OUT_OF_MEMORY;
        }
    }

    *aDestArray = iids;
    return NS_OK;
}
コード例 #6
0
ファイル: nsJSON.cpp プロジェクト: SoulTrader/mozilla-central
nsresult
nsJSONWriter::WriteToStream(nsIOutputStream *aStream,
                            nsIUnicodeEncoder *encoder,
                            const PRUnichar *aBuffer,
                            uint32_t aLength)
{
  nsresult rv;
  int32_t srcLength = aLength;
  uint32_t bytesWritten;

  // The bytes written to the stream might differ from the PRUnichar size
  int32_t aDestLength;
  rv = encoder->GetMaxLength(aBuffer, srcLength, &aDestLength);
  NS_ENSURE_SUCCESS(rv, rv);

  // create the buffer we need
  char* destBuf = (char *) NS_Alloc(aDestLength);
  if (!destBuf)
    return NS_ERROR_OUT_OF_MEMORY;

  rv = encoder->Convert(aBuffer, &srcLength, destBuf, &aDestLength);
  if (NS_SUCCEEDED(rv))
    rv = aStream->Write(destBuf, aDestLength, &bytesWritten);

  NS_Free(destBuf);
  mDidWrite = true;

  return rv;
}
コード例 #7
0
ファイル: xpctest_params.cpp プロジェクト: aeddi/gecko-dev
/* void testInterfaceIs (in nsIIDPtr aIID, [iid_is (aIID)] in nsQIResult a,
 *                       inout nsIIDPtr bIID, [iid_is (bIID)] inout nsQIResult b,
 *                       out nsIIDPtr rvIID, [iid_is (rvIID), retval] out nsQIResult rv); */
NS_IMETHODIMP nsXPCTestParams::TestInterfaceIs(const nsIID *aIID, void *a,
                                               nsIID **bIID, void **b,
                                               nsIID **rvIID, void **rv)
{
    //
    // Getting the buffers and ownership right here can be a little tricky.
    //

    // The interface pointers are heap-allocated, and b has been AddRef'd
    // by XPConnect for the duration of the call. If we snatch it away from b
    // and leave no trace, XPConnect won't Release it. Since we also need to
    // return an already-AddRef'd pointer in rv, we don't need to do anything
    // special here.
    *rv = *b;

    // rvIID is out-only, so nobody allocated an IID buffer for us. Do that now,
    // and store b's IID in the new buffer.
    *rvIID = static_cast<nsIID*>(NS_Alloc(sizeof(nsID)));
    if (!*rvIID)
        return NS_ERROR_OUT_OF_MEMORY;
    **rvIID = **bIID;

    // Copy the interface pointer from a to b. Since a is in-only, XPConnect will
    // release it upon completion of the call. AddRef it for b.
    *b = a;
    static_cast<nsISupports*>(*b)->AddRef();

    // We already had a buffer allocated for b's IID, so we can re-use it.
    **bIID = *aIID;

    return NS_OK;
}
コード例 #8
0
NS_IMETHODIMP 
nsStreamLoader::OnStartRequest(nsIRequest* request, nsISupports *ctxt)
{
  nsCOMPtr<nsIChannel> chan( do_QueryInterface(request) );
  if (chan) {
    int64_t contentLength = -1;
    chan->GetContentLength(&contentLength);
    if (contentLength >= 0) {
      if (contentLength > UINT32_MAX) {
        // Too big to fit into uint32, so let's bail.
        // XXX we should really make mAllocated and mLength 64-bit instead.
        return NS_ERROR_OUT_OF_MEMORY;
      }
      uint32_t contentLength32 = uint32_t(contentLength);
      // preallocate buffer
      mData = static_cast<uint8_t*>(NS_Alloc(contentLength32));
      if (!mData) {
        return NS_ERROR_OUT_OF_MEMORY;
      }
      mAllocated = contentLength32;
    }
  }
  mContext = ctxt;
  return NS_OK;
}
コード例 #9
0
ファイル: nsMemory.cpp プロジェクト: lofter2011/Icefox
NS_COM_GLUE void*
nsMemory::Clone(const void* ptr, PRSize size)
{
    void* newPtr = NS_Alloc(size);
    if (newPtr)
        memcpy(newPtr, ptr, size);
    return newPtr;
}
コード例 #10
0
nsresult
QTAtomReader::GetFairPlayUserName(nsAString& aUserName)
{
  PRUint32 atom[2];
  PRUint64 offset = 0;
  nsresult rv;

  // Get the starting end offset.
  PRInt64  fileSize;
  PRUint64 endOffset;
  rv = mFile->GetFileSize(&fileSize);
  NS_ENSURE_SUCCESS(rv, rv);
  endOffset = fileSize;

  // Set the atom header size.
  mAtomHdrSize = 8;

  // Get the sample description table atom.
  rv = AtomPathGet("/moov/trak/mdia/minf/stbl/stsd",
                   &atom,
                   &offset,
                   &endOffset);
  NS_ENSURE_SUCCESS(rv, rv);

  // Get the FairPlay DRM atom, skipping the sample description table
  // atom header.
  offset += 16;
  rv = AtomPathGet("/drms", &atom, &offset, &endOffset);
  NS_ENSURE_SUCCESS(rv, rv);

  // Get the FairPlay user name atom, skipping the FairPlay DRM atom header.
  offset += 0x24;
  rv = AtomPathGet("/sinf/schi/name", &atom, &offset, &endOffset);
  NS_ENSURE_SUCCESS(rv, rv);

  // Get the FairPlay user name size and offset.
  offset += 8;
  PRUint32 userNameSize = (PRUint32)(endOffset - offset);

  // Allocate a user name buffer and set up for auto-disposal.
  char* userNameBuffer = (char*) NS_Alloc(userNameSize + 1);
  NS_ENSURE_TRUE(userNameBuffer, NS_ERROR_OUT_OF_MEMORY);
  sbAutoNSMemPtr autoUserNameBuffer(userNameBuffer);

  // Read the user name.
  PRUint32 bytesRead;
  rv = mSeekableStream->Seek(nsISeekableStream::NS_SEEK_SET, offset);
  NS_ENSURE_SUCCESS(rv, rv);
  rv = mInputStream->Read(userNameBuffer, userNameSize, &bytesRead);
  NS_ENSURE_SUCCESS(rv, rv);
  NS_ENSURE_TRUE(bytesRead >= userNameSize, NS_ERROR_FAILURE);
  userNameBuffer[userNameSize] = '\0';

  // Return results.
  aUserName.Assign(NS_ConvertUTF8toUTF16(userNameBuffer));

  return NS_OK;
}
コード例 #11
0
/* readonly attribute nsIDPtr controllerId; */
NS_IMETHODIMP sbMockDevice::GetControllerId(nsID * *aControllerId)
{
  NS_ENSURE_ARG_POINTER(aControllerId);

  *aControllerId = (nsID*)NS_Alloc(sizeof(nsID));
  NS_ENSURE_TRUE(*aControllerId, NS_ERROR_OUT_OF_MEMORY);
  **aControllerId = NS_GET_IID(nsISupports);
  return NS_OK;
}
コード例 #12
0
ファイル: nsimpl.cpp プロジェクト: BBkBlade/e
PRUnichar* wxToUnichar(const wxString& wxstr)
{
    size_t i,len = wxstr.Length();
    PRUnichar* ret = (PRUnichar*)NS_Alloc((len+1) * sizeof(PRUnichar));
    for (i = 0; i < len; ++i)
        *(ret+i) = (PRUnichar)wxstr.GetChar(i);
    *(ret+len) = 0;
    return ret;
}
コード例 #13
0
ファイル: nsIconChannel.cpp プロジェクト: rn10950/RetroZilla
static nsresult
moz_gdk_pixbuf_to_channel(GdkPixbuf* aPixbuf, nsIURI *aURI,
                          nsIChannel **aChannel)
{
  int width = gdk_pixbuf_get_width(aPixbuf);
  int height = gdk_pixbuf_get_height(aPixbuf);
  NS_ENSURE_TRUE(height < 256 && width < 256 && height > 0 && width > 0 &&
                 gdk_pixbuf_get_colorspace(aPixbuf) == GDK_COLORSPACE_RGB &&
                 gdk_pixbuf_get_bits_per_sample(aPixbuf) == 8 &&
                 gdk_pixbuf_get_has_alpha(aPixbuf) &&
                 gdk_pixbuf_get_n_channels(aPixbuf) == 4,
                 NS_ERROR_UNEXPECTED);

  const int n_channels = 4;
  gsize buf_size = 3 + n_channels * height * width;
  PRUint8 * const buf = (PRUint8*)NS_Alloc(buf_size);
  NS_ENSURE_TRUE(buf, NS_ERROR_OUT_OF_MEMORY);
  PRUint8 *out = buf;

  *(out++) = width;
  *(out++) = height;
  *(out++) = 8; // bits of alpha per pixel
  
  const guchar * const pixels = gdk_pixbuf_get_pixels(aPixbuf);
  int rowextra = gdk_pixbuf_get_rowstride(aPixbuf) - width * n_channels;

  // encode the RGB data and the A data
  const guchar * in = pixels;
  PRUint8 *alpha_out = out + height * width * 3;
#ifdef DEBUG
  PRUint8 * const alpha_start = alpha_out;
#endif
  for (int y = 0; y < height; ++y, in += rowextra) {
    for (int x = 0; x < width; ++x) {
      *(out++) = *(in++); // R
      *(out++) = *(in++); // G
      *(out++) = *(in++); // B
      *(alpha_out++) = *(in++); // A
    }
  }

  NS_ASSERTION(out == alpha_start && alpha_out == buf + buf_size,
               "size miscalculation");

  nsresult rv;
  nsCOMPtr<nsIInputStream> stream;
  rv = NS_NewByteInputStream(getter_AddRefs(stream), (char*)buf, buf_size);
  NS_ENSURE_SUCCESS(rv, rv);

  nsCOMPtr<nsIStringInputStream> sstream = do_QueryInterface(stream);
  sstream->AdoptData((char*)buf, buf_size); // previous call was |ShareData|

  rv = NS_NewInputStreamChannel(aChannel, aURI, stream,
                                NS_LITERAL_CSTRING("image/icon"));
  return rv;
}
コード例 #14
0
static char* p2cstrdup(StringPtr pstr)
{
  int len = pstr[0];
  char* cstr = static_cast<char*>(NS_Alloc(len + 1));
  if (cstr) {
    memmove(cstr, pstr + 1, len);
    cstr[len] = '\0';
  }
  return cstr;
}
コード例 #15
0
ファイル: nsCRTGlue.cpp プロジェクト: ashishrana7/firefox
char16_t*
NS_strndup(const char16_t* aString, uint32_t aLen)
{
  char16_t* newBuf = (char16_t*)NS_Alloc((aLen + 1) * sizeof(char16_t));
  if (newBuf) {
    memcpy(newBuf, aString, aLen * sizeof(char16_t));
    newBuf[aLen] = '\0';
  }
  return newBuf;
}
コード例 #16
0
// Caller is responsible for freeing returned buffer.
static char* CFStringRefToUTF8Buffer(CFStringRef cfString)
{
  int bufferLength = ::CFStringGetLength(cfString) + 1;
  char* newBuffer = static_cast<char*>(NS_Alloc(bufferLength));
  if (newBuffer && !::CFStringGetCString(cfString, newBuffer, bufferLength, kCFStringEncodingUTF8)) {
    NS_Free(newBuffer);
    newBuffer = nsnull;
  }
  return newBuffer;
}
コード例 #17
0
PRUnichar*
NS_strndup(const PRUnichar *aString, PRUint32 aLen)
{
  PRUnichar *newBuf = (PRUnichar*) NS_Alloc((aLen + 1) * sizeof(PRUnichar));
  if (newBuf) {
    memcpy(newBuf, aString, aLen * sizeof(PRUnichar));
    newBuf[aLen] = '\0';
  }
  return newBuf;
}
コード例 #18
0
NS_IMETHODIMP  nsTextToSubURI::ConvertAndEscape(
  const char *charset, const PRUnichar *text, char **_retval) 
{
  if(nullptr == _retval)
    return NS_ERROR_NULL_POINTER;
  *_retval = nullptr;
  nsresult rv = NS_OK;
  
  // Get Charset, get the encoder.
  nsICharsetConverterManager *ccm;
  rv = CallGetService(kCharsetConverterManagerCID, &ccm);
  if(NS_SUCCEEDED(rv)) {
     nsIUnicodeEncoder *encoder;
     rv = ccm->GetUnicodeEncoder(charset, &encoder);
     NS_RELEASE(ccm);
     if (NS_SUCCEEDED(rv)) {
       rv = encoder->SetOutputErrorBehavior(nsIUnicodeEncoder::kOnError_Replace, nullptr, (PRUnichar)'?');
       if(NS_SUCCEEDED(rv))
       {
          char buf[256];
          char *pBuf = buf;
          int32_t ulen = text ? NS_strlen(text) : 0;
          int32_t outlen = 0;
          if(NS_SUCCEEDED(rv = encoder->GetMaxLength(text, ulen, &outlen))) 
          {
             if(outlen >= 256) {
                pBuf = (char*)NS_Alloc(outlen+1);
             }
             if(nullptr == pBuf) {
                outlen = 255;
                pBuf = buf;
             }
             int32_t bufLen = outlen;
             if(NS_SUCCEEDED(rv = encoder->Convert(text,&ulen, pBuf, &outlen))) {
                // put termination characters (e.g. ESC(B of ISO-2022-JP) if necessary
                int32_t finLen = bufLen - outlen;
                if (finLen > 0) {
                  if (NS_SUCCEEDED(encoder->Finish((char *)(pBuf+outlen), &finLen)))
                    outlen += finLen;
                }
                pBuf[outlen] = '\0';
                *_retval = nsEscape(pBuf, url_XPAlphas);
                if(nullptr == *_retval)
                  rv = NS_ERROR_OUT_OF_MEMORY;
             }
          }
          if(pBuf != buf)
             NS_Free(pBuf);
       }
       NS_RELEASE(encoder);
     }
  }
  
  return rv;
}
コード例 #19
0
char*
NS_strdup(const char *aString)
{
  PRUint32 len = strlen(aString);
  char *str = (char*) NS_Alloc(len + 1);
  if (str) {
    memcpy(str, aString, len);
    str[len] = '\0';
  }
  return str;
}
コード例 #20
0
NS_IMETHODIMP
sbCDDeviceMarshall::GetId(nsID **aId)
{
  NS_ENSURE_ARG_POINTER(aId);

  static nsID const id = SB_CDDEVICE_MARSHALL_CID;
  *aId = static_cast<nsID *>(NS_Alloc(sizeof(nsID)));
  **aId = id;

  return NS_OK;
}
コード例 #21
0
ファイル: hyDataBuffer.cpp プロジェクト: hypershell/fireshell
NS_IMETHODIMP hyDataBuffer::Init(PRUint64 aSize) {
    if(mInitialized) {
        return NS_ERROR_NOT_INITIALIZED;
    }
    
    mInitialized = true;
    mBufferSize = aSize;

    mBuffer = (char*)NS_Alloc(aSize);
    return NS_OK;
}
コード例 #22
0
nsresult nsTextToSubURI::convertURItoUnicode(const nsAFlatCString &aCharset,
                                             const nsAFlatCString &aURI, 
                                             bool aIRI, 
                                             nsAString &_retval)
{
  nsresult rv = NS_OK;

  // check for 7bit encoding the data may not be ASCII after we decode
  bool isStatefulCharset = statefulCharset(aCharset.get());

  if (!isStatefulCharset && IsASCII(aURI)) {
    CopyASCIItoUTF16(aURI, _retval);
    return rv;
  }

  if (!isStatefulCharset && aIRI) {
    if (IsUTF8(aURI)) {
      CopyUTF8toUTF16(aURI, _retval);
      return rv;
    }
  }

  // empty charset could indicate UTF-8, but aURI turns out not to be UTF-8.
  NS_ENSURE_FALSE(aCharset.IsEmpty(), NS_ERROR_INVALID_ARG);

  nsCOMPtr<nsICharsetConverterManager> charsetConverterManager;

  charsetConverterManager = do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID, &rv);
  NS_ENSURE_SUCCESS(rv, rv);

  nsCOMPtr<nsIUnicodeDecoder> unicodeDecoder;
  rv = charsetConverterManager->GetUnicodeDecoder(aCharset.get(), 
                                                  getter_AddRefs(unicodeDecoder));
  NS_ENSURE_SUCCESS(rv, rv);
  unicodeDecoder->SetInputErrorBehavior(nsIUnicodeDecoder::kOnError_Signal);

  int32_t srcLen = aURI.Length();
  int32_t dstLen;
  rv = unicodeDecoder->GetMaxLength(aURI.get(), srcLen, &dstLen);
  NS_ENSURE_SUCCESS(rv, rv);

  char16_t *ustr = (char16_t *) NS_Alloc(dstLen * sizeof(char16_t));
  NS_ENSURE_TRUE(ustr, NS_ERROR_OUT_OF_MEMORY);

  rv = unicodeDecoder->Convert(aURI.get(), &srcLen, ustr, &dstLen);

  if (NS_SUCCEEDED(rv))
    _retval.Assign(ustr, dstLen);
  
  NS_Free(ustr);

  return rv;
}
コード例 #23
0
ファイル: nsID.cpp プロジェクト: lofter2011/Icefox
char *nsID::ToString() const
{
    char *res = (char*)NS_Alloc(NSID_LENGTH);

    if (res != NULL) {
        PR_snprintf(res, NSID_LENGTH, gIDFormat,
                    m0, (PRUint32) m1, (PRUint32) m2,
                    (PRUint32) m3[0], (PRUint32) m3[1], (PRUint32) m3[2],
                    (PRUint32) m3[3], (PRUint32) m3[4], (PRUint32) m3[5],
                    (PRUint32) m3[6], (PRUint32) m3[7]);
    }
    return res;
}
コード例 #24
0
NS_IMETHODIMP  nsTextToSubURI::UnEscapeAndConvert(
  const char *charset, const char *text, PRUnichar **_retval) 
{
  if(nullptr == _retval)
    return NS_ERROR_NULL_POINTER;
  if(nullptr == text) {
    // set empty string instead of returning error
    // due to compatibility for old version
    text = "";
  }
  *_retval = nullptr;
  nsresult rv = NS_OK;
  
  // unescape the string, unescape changes the input
  char *unescaped = NS_strdup(text);
  if (nullptr == unescaped)
    return NS_ERROR_OUT_OF_MEMORY;
  unescaped = nsUnescape(unescaped);
  NS_ASSERTION(unescaped, "nsUnescape returned null");

  // Convert from the charset to unicode
  nsCOMPtr<nsICharsetConverterManager> ccm = 
           do_GetService(kCharsetConverterManagerCID, &rv); 
  if (NS_SUCCEEDED(rv)) {
    nsIUnicodeDecoder *decoder;
    rv = ccm->GetUnicodeDecoder(charset, &decoder);
    if (NS_SUCCEEDED(rv)) {
      PRUnichar *pBuf = nullptr;
      int32_t len = strlen(unescaped);
      int32_t outlen = 0;
      if (NS_SUCCEEDED(rv = decoder->GetMaxLength(unescaped, len, &outlen))) {
        pBuf = (PRUnichar *) NS_Alloc((outlen+1)*sizeof(PRUnichar));
        if (nullptr == pBuf)
          rv = NS_ERROR_OUT_OF_MEMORY;
        else {
          if (NS_SUCCEEDED(rv = decoder->Convert(unescaped, &len, pBuf, &outlen))) {
            pBuf[outlen] = 0;
            *_retval = pBuf;
          }
          else
            NS_Free(pBuf);
        }
      }
      NS_RELEASE(decoder);
    }
  }
  NS_Free(unescaped);

  return rv;
}
コード例 #25
0
nsresult
QTAtomReader::GetFairPlayAccountName(nsAString& aAccountName)
{
  PRUint32 atom[2];
  PRUint64 offset = 0;
  nsresult rv;

  // Get the starting end offset.
  PRInt64  fileSize;
  PRUint64 endOffset;
  rv = mFile->GetFileSize(&fileSize);
  NS_ENSURE_SUCCESS(rv, rv);
  endOffset = fileSize;

  // Set the atom header size.
  mAtomHdrSize = 8;

  // Get the meta-data atom.
  rv = AtomPathGet("/moov/udta/meta", &atom, &offset, &endOffset);
  NS_ENSURE_SUCCESS(rv, rv);

  // Get the FairPlay account name atom, skipping the sample description table
  // atom header.
  offset += 12;
  rv = AtomPathGet("/ilst/apID/data", &atom, &offset, &endOffset);
  NS_ENSURE_SUCCESS(rv, rv);

  // Get the FairPlay account name size and offset.
  offset += 16;
  PRUint32 accountNameSize = (PRUint32)(endOffset - offset);

  // Allocate an account name buffer and set up for auto-disposal.
  char* accountNameBuffer = (char*) NS_Alloc(accountNameSize + 1);
  NS_ENSURE_TRUE(accountNameBuffer, NS_ERROR_OUT_OF_MEMORY);
  sbAutoNSMemPtr autoAccountNameBuffer(accountNameBuffer);

  // Read the account name.
  PRUint32 bytesRead;
  rv = mSeekableStream->Seek(nsISeekableStream::NS_SEEK_SET, offset);
  NS_ENSURE_SUCCESS(rv, rv);
  rv = mInputStream->Read(accountNameBuffer, accountNameSize, &bytesRead);
  NS_ENSURE_SUCCESS(rv, rv);
  NS_ENSURE_TRUE(bytesRead >= accountNameSize, NS_ERROR_FAILURE);
  accountNameBuffer[accountNameSize] = '\0';

  // Return results.
  aAccountName.Assign(NS_ConvertUTF8toUTF16(accountNameBuffer));

  return NS_OK;
}
コード例 #26
0
ファイル: nsCOMArray.cpp プロジェクト: Nazi-Nigger/gecko-dev
uint32_t
nsCOMArray_base::Forget(nsISupports*** aElements)
{
    uint32_t length = Length();
    size_t array_size = sizeof(nsISupports*) * length;
    nsISupports** array = static_cast<nsISupports**>(NS_Alloc(array_size));
    memmove(array, Elements(), array_size);
    *aElements = array;
    // Don't Release the contained pointers; the caller of the method will
    // do this eventually.
    mArray.Clear();

    return length;
}
コード例 #27
0
NS_IMETHODIMP nsMimeHeaders::GetAllHeaders(char **_retval)
{
  NS_ENSURE_ARG_POINTER(_retval);
  NS_ENSURE_TRUE(mHeaders, NS_ERROR_NOT_INITIALIZED);
  NS_ENSURE_TRUE(mHeaders->all_headers, NS_ERROR_NULL_POINTER);

  char *allHeaders = (char *) NS_Alloc(mHeaders->all_headers_fp + 1);
  NS_ENSURE_TRUE(allHeaders, NS_ERROR_OUT_OF_MEMORY);

  memcpy(allHeaders, mHeaders->all_headers, mHeaders->all_headers_fp);
  *(allHeaders + mHeaders->all_headers_fp) = 0;
  *_retval = allHeaders;

  return NS_OK;
}
コード例 #28
0
NS_IMETHODIMP
sbIPDDevice::GetId(nsID** aId)
{
  // Validate parameters.
  NS_ENSURE_ARG_POINTER(aId);

  // Allocate an nsID.
  nsID* pId = static_cast<nsID*>(NS_Alloc(sizeof(nsID)));
  NS_ENSURE_TRUE(pId, NS_ERROR_OUT_OF_MEMORY);

  // Return the ID.
  *pId = mDeviceID;
  *aId = pId;

  return NS_OK;
}
コード例 #29
0
NS_IMETHODIMP
sbCDDeviceController::GetMarshallId(nsID **aId)
{
  NS_ENSURE_ARG_POINTER(aId);

  *aId = nsnull;
  *aId = static_cast<nsID *>(NS_Alloc(sizeof(nsID)));
  nsresult rv = GetMarshallIdInternal(**aId);

  if (NS_FAILED(rv)) {
    NS_Free(*aId);
    *aId = nsnull;
  }

  return NS_OK;
}
コード例 #30
0
ファイル: nsUUIDGenerator.cpp プロジェクト: lofter2011/Icefox
NS_IMETHODIMP
nsUUIDGenerator::GenerateUUID(nsID** ret)
{
    nsID *id = static_cast<nsID*>(NS_Alloc(sizeof(nsID)));
    if (id == nsnull)
        return NS_ERROR_OUT_OF_MEMORY;

    nsresult rv = GenerateUUIDInPlace(id);
    if (NS_FAILED(rv)) {
        NS_Free(id);
        return rv;
    }

    *ret = id;
    return rv;
}