[test][hwasan] Rename constants in test
authorVitaly Buka <vitalybuka@google.com>
Wed, 14 Jun 2023 07:58:05 +0000 (00:58 -0700)
committerVitaly Buka <vitalybuka@google.com>
Wed, 14 Jun 2023 08:00:35 +0000 (01:00 -0700)
compiler-rt/test/hwasan/TestCases/munmap.c

index 3c4ffde..f25e488 100644 (file)
@@ -9,13 +9,12 @@
 #include <sys/mman.h>
 
 int main(int argc, char **argv) {
-  int size = 4096;
-  int tag = 74;
-  int val = 42;
+  const int kSize = 4096;
+  const int kTag = 74;
 
   // Get any mmaped pointer.
   void *r =
-      mmap(0, size, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0);
+      mmap(0, kSize, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0);
   if (r == MAP_FAILED) {
     fprintf(stderr, "Failed to mmap.\n");
     abort();
@@ -28,23 +27,23 @@ int main(int argc, char **argv) {
   }
 
   // Manually tag the pointer and the memory.
-  __hwasan_tag_memory(r, tag, size);
-  int *p1 = __hwasan_tag_pointer(r, tag);
+  __hwasan_tag_memory(r, kTag, kSize);
+  int *p1 = __hwasan_tag_pointer(r, kTag);
 
   // Check that the pointer and the tag match.
-  if (__hwasan_test_shadow(p1, size) != -1) {
+  if (__hwasan_test_shadow(p1, kSize) != -1) {
     fprintf(stderr, "Failed to tag.\n");
     return 1;
   }
 
   // First munmmap and then mmap the same pointer using MAP_FIXED.
-  munmap(r, size);
-  if (__hwasan_test_shadow(r, size) != -1) {
+  munmap(r, kSize);
+  if (__hwasan_test_shadow(r, kSize) != -1) {
     fprintf(stderr, "Shadow memory was not cleaned by munmap.\n");
     return 1;
   }
-  __hwasan_tag_memory(r, tag, size);
-  int *p2 = (int *)mmap(r, size, PROT_READ | PROT_WRITE,
+  __hwasan_tag_memory(r, kTag, kSize);
+  int *p2 = (int *)mmap(r, kSize, PROT_READ | PROT_WRITE,
                         MAP_FIXED | MAP_ANON | MAP_PRIVATE, -1, 0);
 
   // Check that the pointer has no tag in it.
@@ -54,7 +53,7 @@ int main(int argc, char **argv) {
   }
 
   // Make sure we can access the shadow with an untagged pointer.
-  if (__hwasan_test_shadow(p2, size) != -1 ) {
+  if (__hwasan_test_shadow(p2, kSize) != -1) {
     fprintf(stderr, "Shadow memory was not cleaned by mmap.\n");
     return 1;
   }