[Sanitizer] Remove implicit conversion of InternalScopedBuffer<T> to T*

llvm-svn: 163197
This commit is contained in:
Alexey Samsonov 2012-09-05 07:23:44 +00:00
parent f7c87d6eea
commit ceffb021c5
9 changed files with 26 additions and 26 deletions

View File

@ -67,7 +67,6 @@ class InternalScopedBuffer {
~InternalScopedBuffer() {
UnmapOrDie(ptr_, cnt_ * sizeof(T));
}
operator T*() { return ptr_; }
T &operator[](uptr i) { return ptr_[i]; }
T *data() { return ptr_; }
uptr size() { return cnt_ * sizeof(T); }

View File

@ -113,15 +113,16 @@ class ExternalSymbolizer {
// large debug info.
static const int kMaxBufferSize = 4096;
InternalScopedBuffer<char> buffer(kMaxBufferSize);
internal_snprintf(buffer, kMaxBufferSize, "%s 0x%zx\n",
char *buffer_data = buffer.data();
internal_snprintf(buffer_data, kMaxBufferSize, "%s 0x%zx\n",
module_name, module_offset);
if (!writeToSymbolizer(buffer, internal_strlen(buffer)))
if (!writeToSymbolizer(buffer_data, internal_strlen(buffer_data)))
return 0;
if (!readFromSymbolizer(buffer, kMaxBufferSize))
if (!readFromSymbolizer(buffer_data, kMaxBufferSize))
return 0;
const char *str = buffer.data();
int frame_id;
const char *str = buffer_data;
uptr frame_id;
CHECK_GT(max_frames, 0);
for (frame_id = 0; frame_id < max_frames; frame_id++) {
AddressInfo *info = &frames[frame_id];

View File

@ -126,17 +126,17 @@ static int dl_iterate_phdr_cb(dl_phdr_info *info, size_t size, void *arg) {
if (data->current_n == 0) {
// First module is the binary itself.
uptr module_name_len = readlink("/proc/self/exe",
module_name, module_name.size());
module_name.data(), module_name.size());
CHECK_NE(module_name_len, (uptr)-1);
CHECK_LT(module_name_len, module_name.size());
module_name[module_name_len] = '\0';
} else if (info->dlpi_name) {
internal_strncpy(module_name, info->dlpi_name, module_name.size());
internal_strncpy(module_name.data(), info->dlpi_name, module_name.size());
}
if (module_name.data()[0] == '\0')
return 0;
void *mem = &data->modules[data->current_n];
LoadedModule *cur_module = new(mem) LoadedModule(module_name,
LoadedModule *cur_module = new(mem) LoadedModule(module_name.data(),
info->dlpi_addr);
data->current_n++;
for (int i = 0; i < info->dlpi_phnum; i++) {

View File

@ -31,10 +31,10 @@ void TsanPrintf(const char *format, ...) {
InternalScopedBuffer<char> buffer(kMaxLen);
va_list args;
va_start(args, format);
uptr len = VSNPrintf(buffer, buffer.size(), format, args);
uptr len = VSNPrintf(buffer.data(), buffer.size(), format, args);
va_end(args);
internal_write(CTX() ? flags()->log_fileno : 2,
buffer, len < buffer.size() ? len : buffer.size() - 1);
buffer.data(), len < buffer.size() ? len : buffer.size() - 1);
}
} // namespace __tsan

View File

@ -122,8 +122,8 @@ static void MemoryProfileThread(void *arg) {
fd_t fd = (fd_t)(uptr)arg;
for (int i = 0; ; i++) {
InternalScopedBuffer<char> buf(4096);
WriteMemoryProfile(buf, buf.size(), i);
internal_write(fd, buf, internal_strlen(buf));
WriteMemoryProfile(buf.data(), buf.size(), i);
internal_write(fd, buf.data(), internal_strlen(buf.data()));
SleepForSeconds(1);
}
}
@ -132,9 +132,9 @@ static void InitializeMemoryProfile() {
if (flags()->profile_memory == 0 || flags()->profile_memory[0] == 0)
return;
InternalScopedBuffer<char> filename(4096);
internal_snprintf(filename, filename.size(), "%s.%d",
internal_snprintf(filename.data(), filename.size(), "%s.%d",
flags()->profile_memory, GetPid());
fd_t fd = internal_open(filename, true);
fd_t fd = internal_open(filename.data(), true);
if (fd == kInvalidFd) {
TsanPrintf("Failed to open memory profile file '%s'\n", &filename[0]);
Die();

View File

@ -296,7 +296,7 @@ void RestoreStack(int tid, const u64 epoch, StackTrace *stk) {
if (pos == 0 && stack[0] == 0)
return;
pos++;
stk->Init(stack, pos);
stk->Init(stack.data(), pos);
}
static bool HandleRacyStacks(ThreadState *thr, const StackTrace (&traces)[2],

View File

@ -28,10 +28,10 @@ static char *ReadFile(const char *filename) {
return 0;
InternalScopedBuffer<char> tmp(4*1024);
if (filename[0] == '/')
internal_snprintf(tmp, tmp.size(), "%s", filename);
internal_snprintf(tmp.data(), tmp.size(), "%s", filename);
else
internal_snprintf(tmp, tmp.size(), "%s/%s", GetPwd(), filename);
fd_t fd = internal_open(tmp, false);
internal_snprintf(tmp.data(), tmp.size(), "%s/%s", GetPwd(), filename);
fd_t fd = internal_open(tmp.data(), false);
if (fd == kInvalidFd) {
TsanPrintf("ThreadSanitizer: failed to open suppressions file '%s'\n",
tmp.data());

View File

@ -50,7 +50,7 @@ ReportStack *SymbolizeCode(uptr addr) {
InternalScopedBuffer<AddressInfo> addr_frames(kMaxAddrFrames);
for (uptr i = 0; i < kMaxAddrFrames; i++)
new(&addr_frames[i]) AddressInfo();
uptr addr_frames_num = __sanitizer::SymbolizeCode(addr, addr_frames,
uptr addr_frames_num = __sanitizer::SymbolizeCode(addr, addr_frames.data(),
kMaxAddrFrames);
if (addr_frames_num == 0)
return NewReportStackEntry(addr);

View File

@ -87,7 +87,7 @@ static int dl_iterate_phdr_cb(dl_phdr_info *info, size_t size, void *arg) {
DlIteratePhdrCtx *ctx = (DlIteratePhdrCtx*)arg;
InternalScopedBuffer<char> tmp(128);
if (ctx->is_first) {
internal_snprintf(tmp, tmp.size(), "/proc/%d/exe", GetPid());
internal_snprintf(tmp.data(), tmp.size(), "/proc/%d/exe", GetPid());
info->dlpi_name = tmp.data();
}
ctx->is_first = false;
@ -160,7 +160,7 @@ ReportStack *SymbolizeCodeAddr2Line(uptr addr) {
Die();
}
InternalScopedBuffer<char> func(1024);
ssize_t len = internal_read(m->inp_fd, func, func.size() - 1);
ssize_t len = internal_read(m->inp_fd, func.data(), func.size() - 1);
if (len <= 0) {
TsanPrintf("ThreadSanitizer: can't read from symbolizer (%d, %d)\n",
m->inp_fd, errno);
@ -170,11 +170,11 @@ ReportStack *SymbolizeCodeAddr2Line(uptr addr) {
ReportStack *res = NewReportStackEntry(addr);
res->module = internal_strdup(m->name);
res->offset = offset;
char *pos = (char*)internal_strchr(func, '\n');
char *pos = (char*)internal_strchr(func.data(), '\n');
if (pos && func[0] != '?') {
res->func = (char*)internal_alloc(MBlockReportStack, pos - func + 1);
internal_memcpy(res->func, func, pos - func);
res->func[pos - func] = 0;
res->func = (char*)internal_alloc(MBlockReportStack, pos - func.data() + 1);
internal_memcpy(res->func, func.data(), pos - func.data());
res->func[pos - func.data()] = 0;
char *pos2 = (char*)internal_strchr(pos, ':');
if (pos2) {
res->file = (char*)internal_alloc(MBlockReportStack, pos2 - pos - 1 + 1);