Example #1
0
void StringBuffer::absorb(StringBuffer &buf) {
  if (empty()) {
    TAINT_OBSERVER_REGISTER_ACCESSED(buf.getTaintDataRefConst());
    TAINT_OBSERVER_REGISTER_MUTATED(m_taint_data, dataIgnoreTaint());

    StringData* str = m_str;

    m_str = buf.m_str;
    m_buffer = buf.m_buffer;
    m_len = buf.m_len;
    m_cap = buf.m_cap;

    buf.m_str = str;
    if (str) {
      buf.m_buffer = (char*)str->data();
      buf.m_len = str->size();
      buf.m_cap = str->capacity();
    } else {
      buf.m_buffer = 0;
      buf.m_len = 0;
      buf.m_cap = 0;
    }
    buf.reset();
  } else {
    // REGISTER_ACCESSED()/REGISTER_MUTATED() are called by append()/detach()
    append(buf.detach());
  }
}
Example #2
0
CstrBuffer::CstrBuffer(const char *filename)
  : m_buffer(NULL), m_len(0) {
  struct stat sb;
  if (stat(filename, &sb) == 0) {
    if (sb.st_size > kMaxCap - 1) {
      std::ostringstream out;
      out << "file " << filename << " is too large";
      throw StringBufferLimitException(kMaxCap,
                                       String(out.str().c_str()));
    }
    m_cap = sb.st_size;
    m_buffer = (char *)Util::safe_malloc(m_cap + 1);

    int fd = ::open(filename, O_RDONLY);
    if (fd != -1) {
      while (m_len < m_cap) {
        int buffer_size = m_cap - m_len;
        int len = ::read(fd, m_buffer + m_len, buffer_size);
        if (len == -1 && errno == EINTR) continue;
        if (len <= 0) break;
        m_len += len;
      }
      ::close(fd);
    }
  }
  TAINT_OBSERVER_REGISTER_MUTATED(m_taint_data, dataIgnoreTaint());
}
Example #3
0
StringBuffer::StringBuffer(int initialSize /* = 63 */)
  : m_initialCap(initialSize), m_maxBytes(kDefaultOutputLimit),
    m_cap(initialSize), m_len(0) {
  ASSERT(initialSize > 0);
  m_str = NEW(StringData)(initialSize);
  m_buffer = (char *)m_str->data();
  TAINT_OBSERVER_REGISTER_MUTATED(m_taint_data, dataIgnoreTaint());
}
Example #4
0
StringBuffer::StringBuffer(int initialSize /* = 63 */)
  : m_initialCap(initialSize), m_maxBytes(kDefaultOutputLimit),
    m_len(0) {
  assert(initialSize > 0);
  m_str = NEW(StringData)(initialSize);
  MutableSlice s = m_str->mutableSlice();
  m_buffer = s.ptr;
  m_cap = s.len;
  TAINT_OBSERVER_REGISTER_MUTATED(m_taint_data, dataIgnoreTaint());
}
Example #5
0
void StringBuffer::absorb(StringBuffer &buf) {
  if (empty()) {
    TAINT_OBSERVER_REGISTER_ACCESSED(buf.getTaintDataRefConst());
    TAINT_OBSERVER_REGISTER_MUTATED(m_taint_data, dataIgnoreTaint());

    char *buffer = m_buffer;
    int size = m_size;

    m_buffer = buf.m_buffer;
    m_size = buf.m_size;
    m_pos = buf.m_pos;

    buf.m_buffer = buffer;
    buf.m_size = size;
    buf.reset();
  } else {
    // REGISTER_ACCESSED()/REGISTER_MUTATED() are called by append()/detach()
    append(buf.detach());
  }
}
Example #6
0
StringBuffer::StringBuffer(const char *filename)
  : m_buffer(NULL), m_initialSize(1024), m_maxBytes(0), m_size(0), m_pos(0) {
  struct stat sb;
  if (stat(filename, &sb) == 0) {
    m_size = sb.st_size;
    m_buffer = (char *)Util::safe_malloc(m_size + 1);

    int fd = ::open(filename, O_RDONLY);
    if (fd != -1) {
      while (m_pos < m_size) {
        int buffer_size = m_size - m_pos;
        int len = ::read(fd, m_buffer + m_pos, buffer_size);
        if (len == -1 && errno == EINTR) continue;
        if (len <= 0) break;
        m_pos += len;
      }
      ::close(fd);
    }
  }
  TAINT_OBSERVER_REGISTER_MUTATED(m_taint_data, dataIgnoreTaint());
}
Example #7
0
CstrBuffer::CstrBuffer(int cap)
  : m_buffer((char*)Util::safe_malloc(cap + 1)), m_len(0), m_cap(cap) {
  ASSERT(unsigned(cap) <= kMaxCap);
  TAINT_OBSERVER_REGISTER_MUTATED(m_taint_data, dataIgnoreTaint());
}
Example #8
0
StringBuffer::StringBuffer(char *data, int len)
  : m_buffer(data), m_initialSize(1024), m_maxBytes(0), m_size(len),
    m_pos(len) {
  TAINT_OBSERVER_REGISTER_MUTATED(m_taint_data, dataIgnoreTaint());
}
Example #9
0
StringBuffer::StringBuffer(int initialSize /* = 1024 */)
  : m_initialSize(initialSize), m_maxBytes(0), m_size(initialSize), m_pos(0) {
  ASSERT(initialSize > 0);
  m_buffer = (char *)Util::safe_malloc(initialSize + 1);
  TAINT_OBSERVER_REGISTER_MUTATED(m_taint_data, dataIgnoreTaint());
}