More null checks for data coming from clang

This commit is contained in:
Strahinja Val Markovic 2012-08-04 19:29:11 -07:00
parent 3c65c84c7b
commit 5646eeab5e

View File

@ -59,6 +59,8 @@ std::string CXStringToString( CXString text )
std::string ChunkToString( CXCompletionString completion_string, int chunk_num ) std::string ChunkToString( CXCompletionString completion_string, int chunk_num )
{ {
if ( !completion_string )
return std::string();
return CXStringToString( return CXStringToString(
clang_getCompletionChunkText( completion_string, chunk_num ) ); clang_getCompletionChunkText( completion_string, chunk_num ) );
} }
@ -69,6 +71,8 @@ std::string ChunkToString( CXCompletionString completion_string, int chunk_num )
// deprecated etc. // deprecated etc.
bool CompletionStringAvailable( CXCompletionString completion_string ) bool CompletionStringAvailable( CXCompletionString completion_string )
{ {
if ( !completion_string )
return false;
return clang_getCompletionAvailability( completion_string ) == return clang_getCompletionAvailability( completion_string ) ==
CXAvailability_Available; CXAvailability_Available;
} }
@ -159,6 +163,9 @@ CompletionData CompletionResultToCompletionData(
CompletionData data; CompletionData data;
CXCompletionString completion_string = completion_result.CompletionString; CXCompletionString completion_string = completion_result.CompletionString;
if ( !completion_string )
return data;
uint num_chunks = clang_getNumCompletionChunks( completion_string ); uint num_chunks = clang_getNumCompletionChunks( completion_string );
bool saw_left_paren = false; bool saw_left_paren = false;
bool saw_function_params = false; bool saw_function_params = false;
@ -211,8 +218,10 @@ std::vector< CompletionData > ToCompletionDataVector(
CXCodeCompleteResults *results ) CXCodeCompleteResults *results )
{ {
std::vector< CompletionData > completions; std::vector< CompletionData > completions;
completions.reserve( results->NumResults ); if ( !results || !results->Results )
return completions;
completions.reserve( results->NumResults );
unordered_map< std::string, uint > seen_data; unordered_map< std::string, uint > seen_data;
for ( uint i = 0; i < results->NumResults; ++i ) for ( uint i = 0; i < results->NumResults; ++i )