From: Chandler Carruth Date: Tue, 4 Aug 2015 03:53:04 +0000 (+0000) Subject: [UB] Avoid a really broken call to realloc that would later result in X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8fd59d7392e488f9deac24ddc3a59e2293b5897b;p=clang [UB] Avoid a really broken call to realloc that would later result in a bad call to memcpy. When we only have a buffer from one of the two reparse calls, we can just return that buffer rather than going through the realloc/memcpy dance. Found with UBsan. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@243950 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/tools/c-index-test/c-index-test.c b/tools/c-index-test/c-index-test.c index 980f341824..eeeb832cd8 100644 --- a/tools/c-index-test/c-index-test.c +++ b/tools/c-index-test/c-index-test.c @@ -255,6 +255,17 @@ static int parse_remapped_files_with_try(int try_idx, if (ret) return ret; + if (num_unsaved_files_no_try_idx == 0) { + *unsaved_files = unsaved_files_try_idx; + *num_unsaved_files = num_unsaved_files_try_idx; + return 0; + } + if (num_unsaved_files_try_idx == 0) { + *unsaved_files = unsaved_files_no_try_idx; + *num_unsaved_files = num_unsaved_files_no_try_idx; + return 0; + } + *num_unsaved_files = num_unsaved_files_no_try_idx + num_unsaved_files_try_idx; *unsaved_files = (struct CXUnsavedFile *)realloc(unsaved_files_no_try_idx,