Skip to content

Commit

Permalink
Fixed undefined behavior in testing infrastructure
Browse files Browse the repository at this point in the history
  • Loading branch information
cmlsharp committed Jun 4, 2017
1 parent 2fba01d commit db1aa2b
Show file tree
Hide file tree
Showing 15 changed files with 36 additions and 37 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ CC = gcc
EMCC = /usr/lib/emscripten/emcc
EMCONF = /usr/lib/emscripten/emconfigure
SDLINC = /usr/include/SDL2
CFLAGS = -Wall -Wextra -Werror -Wno-unused-function -Wno-unused-parameter -pipe -D_XOPEN_SOURCE=500 -std=c11 -fPIC -I$(INCDIR) -I$(SDLINC) -ggdb3 -O0
CFLAGS = -Wall -Wextra -Werror -Wno-unused-function -Wno-unused-parameter -pipe -D_XOPEN_SOURCE=500 -std=c11 -fPIC -I$(INCDIR) -I$(SDLINC) -ggdb3 -O2
TARGET = lib$(NAME).so

SRCDIR = src
Expand Down
4 changes: 2 additions & 2 deletions src/bst.c
Original file line number Diff line number Diff line change
Expand Up @@ -752,7 +752,7 @@ void testBSTModule(void) {
/* Private functions */

static void testStringBST(void) {
BST bst, bst2;
BST volatile bst, bst2;

trace(bst = newBST(string));
trace(insertArray(bst, ELEMENTS, N_ELEMENTS));
Expand All @@ -770,7 +770,7 @@ static void testStringBST(void) {
}

static void testIntBST(void) {
BST bst, bst2;
BST volatile bst, bst2;

trace(bst = newBST(int));
trace(insertArray(bst, PRIMES, N_PRIMES));
Expand Down
4 changes: 2 additions & 2 deletions src/charset.c
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,8 @@ static CharSet createCharSet(string str);
/* Unit test */

void testCharSetModule(void) {
CharSet vowels, consonants, lowercase, onePointTiles, onePointConsonants;
CharSet set;
CharSet volatile vowels, consonants, lowercase, onePointTiles, onePointConsonants;
CharSet volatile set;

trace(vowels = createCharSet("aeiou"));
trace(consonants = createCharSet("bcdfghjklmnpqrstvwxyz"));
Expand Down
2 changes: 1 addition & 1 deletion src/gevents.c
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ GTimer getGTimer(GEvent e) {
/* Unit test */

void testGEventsModule(void) {
GEvent e;
GEvent volatile e;

trace(e = newGMouseEvent(MOUSE_CLICKED, NULL, 2.3, 4.5));
test(getEventClass(e), (int) MOUSE_EVENT);
Expand Down
8 changes: 4 additions & 4 deletions src/graph.c
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ static void linkNodesAlphabetically(Graph g) {

static void testNodeIterator(Graph g) {
Node node;
int count;
int volatile count;

count = 0;
reportMessage("foreach (node in getNodes(g)) {");
Expand All @@ -373,7 +373,7 @@ static void testNodeIterator(Graph g) {

static void testArcIterator(Graph g) {
Arc arc;
int count;
int volatile count;

count = 0;
reportMessage("foreach (arc in getArcSet(g)) {");
Expand All @@ -390,7 +390,7 @@ static void testArcIterator(Graph g) {

static void testArcsFrom(Graph g) {
Arc arc;
int count;
int volatile count;

count = 0;
reportMessage("foreach (arc in getArcSet(getNode(g, \"A\"))) {");
Expand All @@ -407,7 +407,7 @@ static void testArcsFrom(Graph g) {

static void testNeighbors(Graph g) {
Node node;
int count;
int volatile count;

count = 0;
reportMessage("foreach (node in getNeighbors(getNode(g, \"A\"))) {");
Expand Down
6 changes: 3 additions & 3 deletions src/hashmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,8 @@ static int hashCode(string str) {
}

static void rehash(HashMap map, int nBuckets) {
Cell **oldBuckets, *cp, *np;
int oldNBuckets, bucket, i;
Cell ** volatile oldBuckets, *cp, *np;
int oldNBuckets = 0, bucket, i;

if (map->count != 0) {
oldBuckets = map->buckets;
Expand Down Expand Up @@ -292,7 +292,7 @@ static void markElement(string name, int *bitSet);
/* Unit test */

void testHashMapModule(void) {
HashMap map, map2;
HashMap volatile map, map2;
string key;
int bits;

Expand Down
4 changes: 2 additions & 2 deletions src/map.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,9 @@ static void addKeyToIterator(BSTNode node, void *data) {
#ifndef _NOTEST_

void testMapModule(void) {
Map map, map2;
Map volatile map, map2;
string key;
string str;
string volatile str;

trace(map = newMap());
test(size(map), 0);
Expand Down
4 changes: 2 additions & 2 deletions src/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,8 @@ static string OPTIONS[] = {
};

void testOptionsModule(void) {
string *args;
HashMap options;
string * volatile args;
HashMap volatile options;

trace(args = parseShellArgs("-count 3 -size 1.5 -trace on -v a0 a1"));
trace(options = parseOptions(args, OPTIONS));
Expand Down
2 changes: 1 addition & 1 deletion src/pqueue.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ static void swapHeapEntries(PriorityQueue pq, int i1, int i2) {
/* Unit test */

void testPriorityQueueModule(void) {
PriorityQueue pq, pq2;
PriorityQueue volatile pq, pq2;

trace(pq = newPriorityQueue());
test(size(pq), 0);
Expand Down
2 changes: 1 addition & 1 deletion src/queue.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ Queue cloneQueue(Queue queue) {
/* Unit test */

void testQueueModule(void) {
Queue queue, queue2;
Queue volatile queue, queue2;

trace(queue = newQueue());
test(isEmpty(queue), true);
Expand Down
6 changes: 3 additions & 3 deletions src/set.c
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ void testSetModule(void) {
}

static void testCharacterSet(void) {
Set vowels, consonants, lowercase, onePointTiles, onePointConsonants;
Set volatile vowels, consonants, lowercase, onePointTiles, onePointConsonants;

trace(vowels = createCharSet("aeiou"));
trace(consonants = createCharSet("bcdfghjklmnpqrstvwxyz"));
Expand All @@ -372,7 +372,7 @@ static Set createCharSet(string str) {
}

static void testStringSet() {
Set ospd3, ospd4, newWords, set;
Set volatile ospd3, ospd4, newWords, set;

trace(ospd3 = newSet(string));
test(isEmpty(ospd3), true);
Expand Down Expand Up @@ -414,7 +414,7 @@ static void addStringsToSet(Set set, string array[], int n) {
}

static void testIntegerSet() {
Set primes, evens, odds, set;
Set volatile primes, evens, odds, set;

trace(primes = createDigitSet("2357"));
trace(evens = createDigitSet("02468"));
Expand Down
2 changes: 1 addition & 1 deletion src/stack.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ static void expandCapacity(Stack stack) {
/* Unit test */

void testStackModule(void) {
Stack stack, stack2;
volatile Stack stack, stack2;

trace(stack = newStack());
test(isEmpty(stack), true);
Expand Down
7 changes: 3 additions & 4 deletions src/strbuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,12 @@ string getString(StringBuffer sb) {
/* Friend functions */

int printfCapacity(string format, va_list args) {
int i, capacity, width, precision, len, lcount;
bool inFormat, dotSeen;
int i, capacity, width = 0, precision = 0, len, lcount = 0;
bool inFormat = false, dotSeen = false;
string str;
char ch;

capacity = 0;
inFormat = false;
for (i = 0; format[i] != '\0'; i++) {
ch = format[i];
if (!inFormat) {
Expand Down Expand Up @@ -268,7 +267,7 @@ static int testCapacity(string format, ...);
/* Unit test */

void testStrbufModule(void) {
string alphabet;
string volatile alphabet;

testStringBufferAppend();
testStringBufferFormat();
Expand Down
18 changes: 9 additions & 9 deletions src/tokenscanner.c
Original file line number Diff line number Diff line change
Expand Up @@ -613,8 +613,8 @@ static void testStringScanner(void) {
}

static void testStreamScanner(void) {
TokenScanner scanner;
FILE *infile;
TokenScanner volatile scanner;
FILE * volatile infile;

trace(scanner = newTokenScanner());
trace(infile = fopen("include/tokenscanner.h", "r"));
Expand Down Expand Up @@ -643,8 +643,8 @@ static void testStreamScanner(void) {
}

static void testScannerNoOptions(void) {
TokenScanner scanner;
string token;
TokenScanner volatile scanner;
string volatile token;

trace(scanner = newTokenScanner());
trace(setInputString(scanner, "cout << \"pi = \" << 3.14159265 << endl;"));
Expand Down Expand Up @@ -683,8 +683,8 @@ static void testScannerNoOptions(void) {
}

static void testScannerLanguageOptions(void) {
TokenScanner scanner;
string token;
TokenScanner volatile scanner;
string volatile token;

trace(scanner = newTokenScanner());
trace(ignoreWhitespace(scanner));
Expand Down Expand Up @@ -738,7 +738,7 @@ static void testScannerLanguageOptions(void) {
}

static void testScanNumbers(void) {
TokenScanner scanner;
TokenScanner volatile scanner;

trace(scanner = newTokenScanner());
trace(ignoreWhitespace(scanner));
Expand All @@ -755,8 +755,8 @@ static void testScanNumbers(void) {
}

static void testScanEscapeSequences(void) {
TokenScanner scanner;
string token;
TokenScanner volatile scanner;
string volatile token;

trace(scanner = newTokenScanner());
trace(scanStrings(scanner));
Expand Down
2 changes: 1 addition & 1 deletion src/vector.c
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ static Iterator newVectorIterator(void *collection) {
/* Unit test */

void testVectorModule(void) {
Vector vec, vec2;
Vector volatile vec, vec2;

trace(vec = newVector());
test(isEmpty(vec), true);
Expand Down

0 comments on commit db1aa2b

Please sign in to comment.