From 5fbc2bf923cc92e08d2654294425115930f95c6a Mon Sep 17 00:00:00 2001 From: Sam Elliott Date: Mon, 5 Jun 2017 20:03:37 -0700 Subject: [PATCH] Updates Ptrdist/ft to be fully checked --- MultiSource/Benchmarks/Ptrdist/ft/Fheap.c | 15 ++++++++------- MultiSource/Benchmarks/Ptrdist/ft/Fheap.h | 6 +++++- MultiSource/Benchmarks/Ptrdist/ft/Fsanity.c | 11 +++++++---- MultiSource/Benchmarks/Ptrdist/ft/Fsanity.h | 4 ++++ MultiSource/Benchmarks/Ptrdist/ft/Fstruct.h | 4 ++++ MultiSource/Benchmarks/Ptrdist/ft/ft.c | 18 ++++++++++-------- MultiSource/Benchmarks/Ptrdist/ft/graph.c | 12 +++++++----- MultiSource/Benchmarks/Ptrdist/ft/graph.h | 4 ++++ MultiSource/Benchmarks/Ptrdist/ft/item.c | 2 ++ MultiSource/Benchmarks/Ptrdist/ft/item.h | 4 ++++ 10 files changed, 55 insertions(+), 25 deletions(-) diff --git a/MultiSource/Benchmarks/Ptrdist/ft/Fheap.c b/MultiSource/Benchmarks/Ptrdist/ft/Fheap.c index 97dccc3b9..5086fd93c 100644 --- a/MultiSource/Benchmarks/Ptrdist/ft/Fheap.c +++ b/MultiSource/Benchmarks/Ptrdist/ft/Fheap.c @@ -37,12 +37,13 @@ */ #include -// CHECKED #include #include #include "Fheap.h" #include "Fstruct.h" +#pragma BOUNDS_CHECKED ON + #ifdef DO_INLINE #define INLINE inline #else @@ -59,7 +60,7 @@ void RemoveChild(_Ptr ); void FixRank(_Ptr , int); INLINE void -InitFHeap() +InitFHeap(void) { int j; @@ -143,7 +144,7 @@ DeleteMin(_Ptr h) if(h1 == NULL) { - free((void*)h); + free(h); return(NULL); } @@ -265,7 +266,7 @@ DeleteMin(_Ptr h) } } - free((void*)h); + free(h); return(min); } @@ -387,7 +388,7 @@ Delete(_Ptr h, _Ptr i) while(h1 != CHILD(i)); } - free((void*)i); + free(i); return(h); } @@ -498,11 +499,11 @@ NewHeap(_Ptr i) { _Ptr h = 0; - h = (HeapP *)calloc(1, sizeof(HeapP)); + h = calloc(1, sizeof(HeapP)); if(h == NULL) { - fprintf(stderr, "Oops, could not malloc\n"); + _Unchecked { fprintf(stderr, "Oops, could not malloc\n"); } exit(1); } ITEM(h) = i; diff --git a/MultiSource/Benchmarks/Ptrdist/ft/Fheap.h b/MultiSource/Benchmarks/Ptrdist/ft/Fheap.h index 379f77bc9..63fd8d0dc 100644 --- a/MultiSource/Benchmarks/Ptrdist/ft/Fheap.h +++ b/MultiSource/Benchmarks/Ptrdist/ft/Fheap.h @@ -51,6 +51,8 @@ */ #include "item.h" +#pragma BOUNDS_CHECKED ON + typedef struct _Heap { _Ptr item; @@ -78,7 +80,7 @@ typedef struct _Heap * Return values: * none */ -void InitFHeap(); +void InitFHeap(void); /* * Create a heap structure. @@ -218,4 +220,6 @@ _Ptr Find(_Ptr h, _Ptr item); */ _Ptr ItemOf(_Ptr h); +#pragma BOUNDS_CHECKED OFF + #endif diff --git a/MultiSource/Benchmarks/Ptrdist/ft/Fsanity.c b/MultiSource/Benchmarks/Ptrdist/ft/Fsanity.c index 3f1cf5d0b..a7c64425e 100644 --- a/MultiSource/Benchmarks/Ptrdist/ft/Fsanity.c +++ b/MultiSource/Benchmarks/Ptrdist/ft/Fsanity.c @@ -32,6 +32,8 @@ #include "Fheap.h" #include "Fstruct.h" +#pragma BOUNDS_CHECKED ON + int SanityCheck1(_Ptr h, _Ptr i) { @@ -149,22 +151,23 @@ PrettyPrint(_Ptr h) if(h == NULL_HEAP) { - printf(" nil "); + _Unchecked { printf(" nil "); } return; } - printf("("); + _Unchecked { printf("("); } h1 = h; do { //PrintItem(ITEM(h1)); - printf("[%u] ", RANK(h1)); + _Unchecked { printf("[%u] ", RANK(h1)); } PrettyPrint(CHILD(h1)); h1 = FORWARD(h1); } while(h1 != h); - printf(")"); + _Unchecked { printf(")"); } } +#pragma BOUNDS_CHECKED OFF diff --git a/MultiSource/Benchmarks/Ptrdist/ft/Fsanity.h b/MultiSource/Benchmarks/Ptrdist/ft/Fsanity.h index ea9d14de8..ce239b7c8 100644 --- a/MultiSource/Benchmarks/Ptrdist/ft/Fsanity.h +++ b/MultiSource/Benchmarks/Ptrdist/ft/Fsanity.h @@ -31,6 +31,8 @@ #ifndef _fsanity_h #define _fsanity_h +#pragma BOUNDS_CHECKED ON + /* * Check the entry ordering in the structure. * @@ -98,4 +100,6 @@ int SanityCheck3(_Ptr h, int rank); */ void PrettyPrint(_Ptr h); +#pragma BOUNDS_CHECKED OFF + #endif diff --git a/MultiSource/Benchmarks/Ptrdist/ft/Fstruct.h b/MultiSource/Benchmarks/Ptrdist/ft/Fstruct.h index 43074a74c..fbddc59d9 100644 --- a/MultiSource/Benchmarks/Ptrdist/ft/Fstruct.h +++ b/MultiSource/Benchmarks/Ptrdist/ft/Fstruct.h @@ -39,6 +39,8 @@ #ifndef _fstruct_h #define _fstruct_h +#pragma BOUNDS_CHECKED ON + #define ITEM(P) ((*(P)).item) #define PARENT(P) ((*(P)).parent) #define CHILD(P) ((*(P)).child) @@ -55,4 +57,6 @@ #define FALSE 0 #define MAX_RANK 10000 +#pragma BOUNDS_CHECKED OFF + #endif diff --git a/MultiSource/Benchmarks/Ptrdist/ft/ft.c b/MultiSource/Benchmarks/Ptrdist/ft/ft.c index 2f8bcf6ae..f99bb68fd 100644 --- a/MultiSource/Benchmarks/Ptrdist/ft/ft.c +++ b/MultiSource/Benchmarks/Ptrdist/ft/ft.c @@ -44,6 +44,8 @@ #include "Fheap.h" #include "graph.h" +#pragma BOUNDS_CHECKED ON + #define MINUS_INFINITY INT_MIN #define PLUS_INFINITY INT_MAX @@ -65,7 +67,7 @@ _Ptr MST(_Ptr graph); */ int debug = 1; -int +_Unchecked int main(int argc, _Array_ptr argv : count(argc) ) { int nVertex; @@ -89,14 +91,14 @@ main(int argc, _Array_ptr argv : count(argc) ) } if(debug) - { + _Unchecked { printf("Generating a connected graph ... "); } graph = GenGraph(nVertex, nEdge); if(debug) - { + _Unchecked { printf("done\nFinding the mininmum spanning tree ... "); } @@ -104,15 +106,15 @@ main(int argc, _Array_ptr argv : count(argc) ) if(debug) { - printf("done\nThe graph:\n"); + _Unchecked { printf("done\nThe graph:\n"); } PrintGraph(graph); - printf("The minimum spanning tree:\n"); + _Unchecked { printf("The minimum spanning tree:\n"); } PrintMST(graph); } if(debug) { - printf("Time spent in finding the mininum spanning tree:\n"); + _Unchecked { printf("Time spent in finding the mininum spanning tree:\n"); } } #ifdef PLUS_STATS PrintDerefStats(stderr); @@ -142,7 +144,7 @@ MST(_Ptr graph) vertex = graph; KEY(vertex) = 0; heap = MakeHeap(); - (void)Insert(&heap, (Item *)vertex); + (void)Insert(&heap, vertex); vertex = NEXT_VERTEX(vertex); while(vertex != graph) @@ -185,7 +187,7 @@ PrintMST(_Ptr graph) while(vertex != graph) { - printf("vertex %d to %d\n", ID(vertex), ID(SOURCE(CHOSEN_EDGE(vertex)))); + _Unchecked { printf("vertex %d to %d\n", ID(vertex), ID(SOURCE(CHOSEN_EDGE(vertex)))); } vertex = NEXT_VERTEX(vertex); } diff --git a/MultiSource/Benchmarks/Ptrdist/ft/graph.c b/MultiSource/Benchmarks/Ptrdist/ft/graph.c index dcee44b6e..2aa344374 100644 --- a/MultiSource/Benchmarks/Ptrdist/ft/graph.c +++ b/MultiSource/Benchmarks/Ptrdist/ft/graph.c @@ -33,6 +33,8 @@ #include #include "graph.h" +#pragma BOUNDS_CHECKED ON + #define TRUE 1 #define FALSE 0 @@ -228,7 +230,7 @@ NewVertex(void) if(vertex == NULL) { - fprintf(stderr, "Could not malloc\n"); + _Unchecked { fprintf(stderr, "Could not malloc\n"); } exit(1); } @@ -248,7 +250,7 @@ NewEdge(void) if(edge == NULL) { - fprintf(stderr, "Could not malloc\n"); + _Unchecked { fprintf(stderr, "Could not malloc\n"); } exit(1); } @@ -269,9 +271,9 @@ PrintGraph(_Ptr graph) vertex = graph; do { - printf("Vertex %d is connected to:", ID(vertex)); + _Unchecked { printf("Vertex %d is connected to:", ID(vertex)); } PrintNeighbors(vertex); - printf("\n"); + _Unchecked { printf("\n"); } vertex = NEXT_VERTEX(vertex); } while(vertex != graph); @@ -285,7 +287,7 @@ PrintNeighbors(_Ptr vertex) edge = EDGES(vertex); while(edge != NULL) { - printf(" %d(%d)[%d]", ID(VERTEX(edge)), WEIGHT(edge), ID(SOURCE(edge))); + _Unchecked { printf(" %d(%d)[%d]", ID(VERTEX(edge)), WEIGHT(edge), ID(SOURCE(edge))); } edge = NEXT_EDGE(edge); } } diff --git a/MultiSource/Benchmarks/Ptrdist/ft/graph.h b/MultiSource/Benchmarks/Ptrdist/ft/graph.h index 6e8022491..fd9a5133d 100644 --- a/MultiSource/Benchmarks/Ptrdist/ft/graph.h +++ b/MultiSource/Benchmarks/Ptrdist/ft/graph.h @@ -31,6 +31,8 @@ #ifndef _graph_h #define _graph_h +#pragma BOUNDS_CHECKED ON + struct _Vertices; typedef struct _Edges @@ -75,4 +77,6 @@ typedef struct _Vertices _Ptr GenGraph(int nVertex, int nEdge); void PrintGraph(_Ptr graph); +#pragma BOUNDS_CHECKED OFF + #endif diff --git a/MultiSource/Benchmarks/Ptrdist/ft/item.c b/MultiSource/Benchmarks/Ptrdist/ft/item.c index b8327142a..75c662c78 100644 --- a/MultiSource/Benchmarks/Ptrdist/ft/item.c +++ b/MultiSource/Benchmarks/Ptrdist/ft/item.c @@ -34,6 +34,8 @@ #include "item.h" +#pragma BOUNDS_CHECKED ON + int LessThan(_Ptr item1, _Ptr item2) { return(KEY(item1) < KEY(item2)); diff --git a/MultiSource/Benchmarks/Ptrdist/ft/item.h b/MultiSource/Benchmarks/Ptrdist/ft/item.h index 819ab7742..7d92a3a02 100644 --- a/MultiSource/Benchmarks/Ptrdist/ft/item.h +++ b/MultiSource/Benchmarks/Ptrdist/ft/item.h @@ -33,6 +33,8 @@ #include "graph.h" +#pragma BOUNDS_CHECKED ON + typedef Vertices Item; #define NULL_ITEM NULL_VERTEX @@ -41,4 +43,6 @@ int LessThan(_Ptr , _Ptr ); int Equal(_Ptr , _Ptr ); _Ptr Subtract(_Ptr , int); +#pragma BOUNDS_CHECKED OFF + #endif