summaryrefslogtreecommitdiffstats
path: root/clang/tools/c-index-test/c-index-test.c
diff options
context:
space:
mode:
authorChandler Carruth <chandlerc@gmail.com>2015-08-04 03:53:04 +0000
committerChandler Carruth <chandlerc@gmail.com>2015-08-04 03:53:04 +0000
commit6ac555fb7118c8e6893d40068d3f9407b4641e41 (patch)
tree97649ffbf8adc45e5850d9c41ed296515b37b849 /clang/tools/c-index-test/c-index-test.c
parent38a45cc686e7110e51e154757302827d384d538e (diff)
downloadbcm5719-llvm-6ac555fb7118c8e6893d40068d3f9407b4641e41.tar.gz
bcm5719-llvm-6ac555fb7118c8e6893d40068d3f9407b4641e41.zip
[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. llvm-svn: 243950
Diffstat (limited to 'clang/tools/c-index-test/c-index-test.c')
-rw-r--r--clang/tools/c-index-test/c-index-test.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/clang/tools/c-index-test/c-index-test.c b/clang/tools/c-index-test/c-index-test.c
index 980f341824f..eeeb832cd87 100644
--- a/clang/tools/c-index-test/c-index-test.c
+++ b/clang/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,
OpenPOWER on IntegriCloud