gfx/angle/src/compiler/preprocessor/Input.cpp

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

     1 //
     2 // Copyright (c) 2011 The ANGLE Project Authors. All rights reserved.
     3 // Use of this source code is governed by a BSD-style license that can be
     4 // found in the LICENSE file.
     5 //
     7 #include "Input.h"
     9 #include <algorithm>
    10 #include <cassert>
    11 #include <cstring>
    13 namespace pp
    14 {
    16 Input::Input() : mCount(0), mString(0)
    17 {
    18 }
    20 Input::Input(size_t count, const char* const string[], const int length[]) :
    21     mCount(count),
    22     mString(string)
    23 {
    24     mLength.reserve(mCount);
    25     for (size_t i = 0; i < mCount; ++i)
    26     {
    27         int len = length ? length[i] : -1;
    28         mLength.push_back(len < 0 ? std::strlen(mString[i]) : len);
    29     }
    30 }
    32 size_t Input::read(char* buf, size_t maxSize)
    33 {
    34     size_t nRead = 0;
    35     while ((nRead < maxSize) && (mReadLoc.sIndex < mCount))
    36     {
    37         size_t size = mLength[mReadLoc.sIndex] - mReadLoc.cIndex;
    38         size = std::min(size, maxSize);
    39         std::memcpy(buf + nRead, mString[mReadLoc.sIndex] + mReadLoc.cIndex, size);
    40         nRead += size;
    41         mReadLoc.cIndex += size;
    43         // Advance string if we reached the end of current string.
    44         if (mReadLoc.cIndex == mLength[mReadLoc.sIndex])
    45         {
    46             ++mReadLoc.sIndex;
    47             mReadLoc.cIndex = 0;
    48         }
    49     }
    50     return nRead;
    51 }
    53 }  // namespace pp

mercurial