Fix use-after-free bugs
UnsavedFile should now actually be storing the data, not just the pointers to it.
This commit is contained in:
parent
c43327d176
commit
6b11edb2e2
@ -112,11 +112,8 @@ std::vector< CXUnsavedFile > ToCXUnsavedFiles(
|
||||
std::vector< CXUnsavedFile > clang_unsaved_files( unsaved_files.size() );
|
||||
|
||||
for ( uint i = 0; i < unsaved_files.size(); ++i ) {
|
||||
X_VERIFY( unsaved_files[ i ].filename_ );
|
||||
X_VERIFY( unsaved_files[ i ].contents_ );
|
||||
X_VERIFY( unsaved_files[ i ].length_ );
|
||||
clang_unsaved_files[ i ].Filename = unsaved_files[ i ].filename_;
|
||||
clang_unsaved_files[ i ].Contents = unsaved_files[ i ].contents_;
|
||||
clang_unsaved_files[ i ].Filename = unsaved_files[ i ].filename_.c_str();
|
||||
clang_unsaved_files[ i ].Contents = unsaved_files[ i ].contents_.c_str();
|
||||
clang_unsaved_files[ i ].Length = unsaved_files[ i ].length_;
|
||||
}
|
||||
|
||||
|
@ -37,6 +37,8 @@ std::string CXStringToString( CXString text );
|
||||
std::vector< CompletionData > ToCompletionDataVector(
|
||||
CXCodeCompleteResults *results );
|
||||
|
||||
// NOTE: CXUnsavedFiles store pointers to data in UnsavedFiles, so UnsavedFiles
|
||||
// need to outlive CXUnsavedFiles!
|
||||
std::vector< CXUnsavedFile > ToCXUnsavedFiles(
|
||||
const std::vector< UnsavedFile > &unsaved_files );
|
||||
|
||||
|
@ -18,13 +18,13 @@
|
||||
#ifndef UNSAVEDFILE_H_0GIYZQL4
|
||||
#define UNSAVEDFILE_H_0GIYZQL4
|
||||
|
||||
#include <cstddef>
|
||||
#include <string>
|
||||
|
||||
struct UnsavedFile {
|
||||
UnsavedFile() : filename_( NULL ), contents_( NULL ), length_( 0 ) {}
|
||||
UnsavedFile() : filename_( "" ), contents_( "" ), length_( 0 ) {}
|
||||
|
||||
const char *filename_;
|
||||
const char *contents_;
|
||||
std::string filename_;
|
||||
std::string contents_;
|
||||
unsigned long length_;
|
||||
|
||||
// We need this to be able to export this struct to Python via Boost.Python's
|
||||
|
Loading…
Reference in New Issue
Block a user