[test][asan] Limit scope of the var
authorVitaly Buka <vitalybuka@google.com>
Sun, 20 Nov 2022 06:24:46 +0000 (22:24 -0800)
committerVitaly Buka <vitalybuka@google.com>
Tue, 22 Nov 2022 00:38:52 +0000 (16:38 -0800)
compiler-rt/test/asan/TestCases/contiguous_container.cpp

index 5cc09cc..2bd31f4 100644 (file)
@@ -24,12 +24,11 @@ void TestContainer(size_t capacity, size_t off_begin, bool poison_buffer) {
   char *st_beg = buffer + off_begin;
   char *st_end = st_beg + capacity;
   char *end = poison_buffer ? st_beg : st_end;
-  char *old_end;
 
   for (int i = 0; i < 1000; i++) {
     size_t size = rand() % (capacity + 1);
     assert(size <= capacity);
-    old_end = end;
+    char *old_end = end;
     end = st_beg + size;
     __sanitizer_annotate_contiguous_container(st_beg, st_end, old_end, end);
 
@@ -51,7 +50,7 @@ void TestContainer(size_t capacity, size_t off_begin, bool poison_buffer) {
   }
 
   for (int i = 0; i <= capacity; i++) {
-    old_end = end;
+    char *old_end = end;
     end = st_beg + i;
     __sanitizer_annotate_contiguous_container(st_beg, st_end, old_end, end);