Solved

How to correct a C6001issue?

Posted on 2015-02-05
5
201 Views
Last Modified: 2015-02-06
Let me first start off by saying I'm not a C++ programmer and I was assigned the task of correcting and compiling a program written by a former employee.

I ran the program through the Code Analysis utility and was able to resolve all issues but one which states "C6001: Using uninitialized memory".  I've initialized the structure to NULL and do not understand why the analyzer is stating I'm using an uninitialized memory.

I've provided a snippet of the code that is in question:

class PATIENT {
private:
      int id;                  // obs number from input SAS dataset
      char gender;             // '2' is female, '1' is male, ' ' missing
      int dxs[maxdxs];         // array of diagnoses
      int ndxs;                // number of diagnoses which patient has
      TRIPLE* head;            // head of linked list of triples
      int inclause(int, char*);// subfunction of without
      int in(int, char*);      // subfunction of inclause
public:
      PATIENT(int, int*);        // constructor
      ~PATIENT();                // destructor
      int match(int, int*);      // check if patient has a diagnosis
      int matchr(DXRANGE, int*); // same, but for diagnosis range
      int without(char*);        // check if patient has none of the diags
      inline int sex(char g);    // check if patient is of this sex
      void attain(TRIPLE*);      // accept a stage which was reached
      void propagate();          // search through rules for matches
      void output();             // write attained triples to file
};

struct STAGE {
      int dxcat;
       int stage;
};

struct TRIPLE {
        STAGE s;
       int p;        // pflag
      TRIPLE* next;
};

....

TRIPLE* t = NULL;
  while (head != NULL)
  {
      t = head->next;       <========\    These two lines are identified as causing the C6001 message
      free(head);              <========/
      head = t;
  }
}

Can someone please provide me with assistance as to making the necessary changes so that this C6001 message is resolved?  Thank you.
0
Comment
Question by:CarmenMTorres
  • 3
  • 2
5 Comments
 
LVL 86

Expert Comment

by:jkr
Comment Utility
C6001 is a message generated bs VS' static code analysis tool, not really an error. And that tool is what the name says: A static analyzer. Could you post the entire function that contains the code which causes the messages?
0
 

Author Comment

by:CarmenMTorres
Comment Utility
I've attached the program.  The lines of code in question are lines 578 and 579; i.e.,

TRIPLE* t = NULL;
  while (head != NULL)   {
      t = head->next;       <========\    These two lines are identified as causing the C6001 message
      free(head);              <========/
      head = t;
  }
}

// Dun & Bradstreet HealthCare Information
// Disease Staging Program v. 2.0 (ORCHARD)
// written by JCS 14SEP95

#define _CRT_SECURE_NO_DEPRECATE
#include <cstdio>
#include <stdio.h>
#include <malloc.h>
#include <stdlib.h>



// class and structure declarations


class PATIENT;         // a patient record
class RULE;            // a rule from the file of pretty rules
class LINK;            // a node in a rule tree
struct TRIPLE;         // a staging triple (dx category, stage, pflag)
class DXLINK;          // single dx link
class DXRLINK;         // dx range link
class STLINK;          // stage link
class XLINK;           // sex link
class WLINK;           // without clause link
struct STAGE;          // dxcat and stage
struct DXRANGE;        // lo and hi dxs


// global variables and constants


const int osize = 1300;   // size of orchard
const int lastdxc = 1700; // no dxcats >= 1700
const int laststag = 50;  // no stages >= 50
const int maxdxs = 50;    // maximum # of dxs a patient can have
const int dxconjlen = 6;  // there are at most this many dxs in conjunction
const int scanlen = 120;  // max length of rule text read in


LINK* orchard[osize];           // top array of trees of rules
LINK* grove[lastdxc][laststag]; // array of pointers to possible stage links
int verbose;                    // whether or not to output all triples


FILE *patfile;
FILE *outfile;
FILE *rulfile;
//FILE *rulefile;
FILE *verbosefile;
FILE *rFile;


const int dxlen = 5;      // # of digits in a dx
const int rangelen = 11;  // length of string specifying dx range
const int stlen = 9;      // length of a dxcat-stage specification
const int reflen = 2;     // length of a stage specification
const int catlen = 4;     // length of a dxcat specification
const int stranlen = 7;   // max length of stage range
const int wolen = 80;     // max length of without clause


// global function declarations

int temp = 0;

void plant(char*);     // create the orchard from file of rules
void harvest(char*);   // use the orchard to process patient records
int dxint(char*);      // converts a dx string to an integer
int ctoi(char);        // turns e.g. '1' to 1, 'E' to 10
char sexfmt(char);     // 'M'/'F' vs. 1,2
STAGE stfmt(char*);    // turns e.g. '0101_1.1' to a structure
inline int bin(char*); // find appropriate tree in orchard
inline int bin(int);   // find appropriate tree in orchard
int superior(TRIPLE*, TRIPLE*);  // chooses the higher stage triple


// class and structure definitions


struct STAGE
{
	int dxcat;
	int stage;
};


struct DXRANGE
{
	int lo;
	int hi;
};


struct TRIPLE
{
	STAGE s;
	int p;        // pflag
	TRIPLE* next;
};


class PATIENT
{
private:
	int id;                  // obs number from input SAS dataset
	char gender;             // '2' is female, '1' is male, ' ' missing
	int dxs[maxdxs];         // array of diagnoses
	int ndxs;                // number of diagnoses which patient has
	TRIPLE* head;            // head of linked list of triples
	int inclause(int, char*);// subfunction of without
	int in(int, char*);      // subfunction of inclause
public:
	PATIENT(int, int*);        // constructor
	~PATIENT();                // destructor
	int match(int, int*);      // check if patient has a diagnosis
	int matchr(DXRANGE, int*); // same, but for diagnosis range
	int without(char*);        // check if patient has none of the diags
	inline int sex(char g);    // check if patient is of this sex
	void attain(TRIPLE*);      // accept a stage which was reached
	void propagate();          // search through rules for matches
	void output();             // write attained triples to file
};


class RULE
{
private:
	char dxconj[dxconjlen][rangelen + 1];  // conjunction of diagnoses
	char woclause[wolen];                // without clause
	char gender;                         // F is female, M is male
	char stagstr[stlen];                 // result string (dxcat and stage)
public:
	RULE(int*);                          // constructor
	void fructify(int, LINK*);           // add to tree in orchard
};


class LINK
{
private:
	LINK* forward;             // next link in list
	LINK* down;                // head of sublist reached from this link
	int hookup(LINK*);         // accept a next link
public:
	LINK();                    // constructor
	inline LINK* advance();    // returns: forward pointer
	inline LINK* descend();    // returns: down pointer
	inline virtual char isa(); // returns: type of link
	LINK* push(LINK*);         // attaches a sublink
	void search(PATIENT*, int);// perform recursive search
};


// LINK class structural functions 

LINK::LINK()
{
	down = NULL;
	forward = NULL;
}

inline LINK* LINK::advance()
{
	return forward;
}

inline LINK* LINK::descend()
{
	return down;
}

inline  char LINK::isa()
{
	return 'h';
}

LINK* LINK::push(LINK* nextl)
{
	if (nextl->hookup(down))
	{
		down = nextl;
		return nextl;
	}
	else
	{
		printf("Error: attempt to violate tree integrity\n");
		exit(1);
	}
}

int LINK::hookup(LINK* prevl)
{
	if (prevl == NULL) return 1;
	else if (forward == NULL)
	{
		forward = prevl;
		return 1;
	}
	else return 0;
}


// LINK child classes


class DXLINK : public LINK
{
private:
	int dx;
public:
	inline int val() { return dx; }
	inline char isa() { return 'd'; }
	DXLINK(int);
};

DXLINK::DXLINK(int v)
{
	dx = v;
	LINK();
}

class DXRLINK : public LINK
{
private:
	DXRANGE dx;
public:
	inline DXRANGE val() { return dx; }
	inline char isa() { return 'D'; }
	DXRLINK(DXRANGE);
};

DXRLINK::DXRLINK(DXRANGE v)
{
	dx = v;
	LINK();
}

class STLINK : public LINK
{
private:
	STAGE st;
public:
	inline STAGE val() { return st; }
	inline char isa() { return 's'; }
	STLINK(STAGE);
};

STLINK::STLINK(STAGE v)
{
	st = v;
	LINK();
}

class XLINK : public LINK
{
private:
	char sex;
public:
	inline char val() { return sex; }
	inline char isa() { return 'x'; }
	XLINK(char);
};

XLINK::XLINK(char v)
{
	sex = v;
	LINK();
}

class WLINK : public LINK
{
private:
	char woclause[wolen];
public:
	inline char* val() { return woclause; }
	inline char isa() { return 'w'; }
	WLINK(char*);
};

WLINK::WLINK(char* v)
{
	int i;
	for (i = 0; i<wolen; i++)
		woclause[i] = v[i];
	LINK();
}


// the main orchard-searching algorithm

void LINK::search(PATIENT* pat, int pflag)
{
	LINK* l = down;
	TRIPLE* t;
	int newpflag;
	while (l != NULL)
	{
		newpflag = pflag;
		switch (l->isa())
		{
		case 'd':
			if (pat->match(((DXLINK*)l)->val(), &newpflag))
				l->search(pat, newpflag);
			break;
		case 'D':
			if (pat->matchr(((DXRLINK*)l)->val(), &newpflag))
				l->search(pat, newpflag);
			break;
		case 's':
			t = (TRIPLE*)malloc(sizeof(TRIPLE));
			if (t) {
				t->p = pflag;
				t->s = ((STLINK*)l)->val();
				pat->attain(t);
				l->search(pat, newpflag);
			}
			break;
		case 'x':
			if (pat->sex(((XLINK*)l)->val()))
				l->search(pat, newpflag);
			break;
		case 'w':
			if (pat->without(((WLINK*)l)->val()))
				l->search(pat, newpflag);
			break;
		default:
			printf("Error: illegal type of link %c\n", l->isa());
			exit(1);
		} // end of switch on link type
		l = l->advance();
	}
} // end of LINK::search


// patient criterion-checking functions

int PATIENT::match(int match, int* pf)
{
	int i;
	if (dxs[0] == match)
	{
		*pf = 1;
		return 1;
	}
	for (i = 1; i<ndxs; i++)
		if (dxs[i] == match) return 1;
	return 0;
}

int PATIENT::matchr(DXRANGE match, int* pf)
{
	int i;
	if ((dxs[0] >= match.lo) && (dxs[0] <= match.hi))
	{
		*pf = 1;
		return 1;
	}
	for (i = 1; i<ndxs; i++)
		if ((dxs[i] >= match.lo) && (dxs[i] <= match.hi)) return 1;
	return 0;
}

int PATIENT::without(char* clause)
{
	int i;
	for (i = 0; i<ndxs; i++)
		if (inclause(dxs[i], clause)) return 0;
	return 1;
}

int PATIENT::inclause(int dx, char* clause)
{
	int i;
	char str[rangelen + 1];
	while (clause[0] != '\0')
	{
		if (clause[0] == ',') clause++;
		i = 0;
		while ((clause[0] != '\0') && (clause[0] != ','))
			str[i++] = (clause++)[0];
		str[i] = '\0';
		if (in(dx, str)) return 1;
	}
	return 0;
} // end of function inclause

int PATIENT::in(int dx, char* comp)
{
	switch (comp[dxlen])
	{
	case '\0': case ',':
		if (dx != dxint(comp)) return 0;
		return 1;
	case '-':
		if ((dx >= dxint(comp)) && (dx <= dxint(comp + dxlen + 1)))
			return 1;
		else return 0;
	default:
		printf("Error: ill-formed dx range %s\n", comp);
		exit(1);
	}
}

inline int PATIENT::sex(char g)
{
	return (gender == g);
}


// other patient functions

void PATIENT::attain(TRIPLE* t)
{
	t->next = head;
	head = t;
	if (verbose) fprintf(verbosefile, "%d,%d,%d,%d\n", id,
		(t->s).dxcat, (t->s).stage, t->p);
}

void PATIENT::propagate()
{
	int i;
	for (i = 0; i<ndxs; i++)
		orchard[bin(dxs[i])]->search(this, 0);
}

void PATIENT::output()
{
	TRIPLE* t, *u, *pr, *se, *blank;
	int delivery = 0;

	blank = (TRIPLE*)malloc(sizeof(TRIPLE));
	if (blank) {
		(blank->s).dxcat = 0;
		(blank->s).stage = -1;
		blank->p = -1;
		pr = blank;
		se = blank;
		t = head;
		while (t != NULL)
		{
			if (t->p)
			{
				u = head;
				while (u != NULL)
				{
					if ((u->s).dxcat == (t->s).dxcat) u->p = 1;
					u = u->next;
				}
			}
			if (((t->s).dxcat == 1101) || ((t->s).dxcat == 1102))
				delivery = 1;
			t = t->next;
		}
		if (delivery)
		{
			t = head;
			while (t != NULL)
			{
				switch ((t->s).dxcat)
				{
				case 1101: case 1102: case 1103: case 1105: case 1106:
				case 1134: case 1135:
					if (superior(t, pr)) pr = t;
					break;
				default:
					if (superior(t, se)) se = t;
				}
				t = t->next;
			}
		}
		else
		{
			t = head;
			while (t != NULL)
			{
				if (t->p)
				{
					if (superior(t, pr)) pr = t;
				}
				else
				{
					if (superior(t, se)) se = t;
				}
				t = t->next;
			}
		}
		fprintf(outfile, "%d,%d,%d,%d,%d,%d,%d\n", id, (pr->s).dxcat,
			(pr->s).stage, pr->p, (se->s).dxcat, (se->s).stage, se->p);
		free(blank);
	}
}

int superior(TRIPLE* contender, TRIPLE* champion)
{
	//float d;
	double d;
	if ((contender->s).stage > (champion->s).stage) return 1;
	d = ((float)(champion->s).dxcat / 100.0);
	if ((int)(10 * (d - (int)d) + 0.01) == 9) return 1;
	return 0;
}

PATIENT::PATIENT(int num, int* fl)
{
//	int i, donefl;
	int donefl;
//	char string[dxlen + 1];
	char string[dxlen + 3];
	donefl = 0;
	ndxs = 0;
	head = NULL;
	id = num;

	//	i = fscanf(patfile, "%s", string);
	while ((fscanf(patfile, "%s", string) != EOF))
	{
		while (!(donefl)) {
			//if (i <= 0) *fl = 1;
			gender = sexfmt(string[0]);

			//while ((*fl == 0) && (ndxs<maxdxs) && (!(donefl)))
			while ((fscanf(patfile, "%s", string) != EOF) && (ndxs < maxdxs) && (!(donefl)))
			{
				//i = fscanf(patfile, "%s", string);
				//if (i <= 0) *fl = 1;
				//else
				//{
				if (string[0] == '+') {
					donefl = 1;
					break;
				}
				else
				{
					dxs[ndxs] = dxint(string);
					ndxs++;
				}
				//}
			}

			if ((ndxs == maxdxs) && (!feof(patfile)))
			{
				donefl = 0;
				// while (!(donefl) && (*fl == 0))
				while (!(donefl) && (fscanf(patfile, "%s", string) != EOF))
				{
					//i = fscanf(patfile, "%s", string);
					//while (fscanf(patfile, "%s", string) != EOF){
					//if (i <= 0) *fl = 1;

					if (string[0] == '+') {
						donefl = 1;
						break;
					}
					else
					{
						printf("Number of diagnoses and procedures on record\n");
						printf("  for patient %d exceeds maximum %d\n", id, maxdxs);
					}
					//}
				}
				if (feof(patfile)) *fl = 1;
			}
		}
		if (donefl == 1) break;
	} 

	if (feof(patfile)) 
		*fl = 1;
}

PATIENT::~PATIENT()
{
	TRIPLE* t = NULL;
	
	while (head != NULL)
	{
		t = head->next;
		free(head);
		head = t;
	}
}


// rule functions

RULE::RULE(int* fl)
{
	char savstr[scanlen];
	char* string;
	int i, j;
	char storechar;
//	if (temp == 14187) 
//		printf("eof");
//	i = fscanf(rFile, "%s", savstr);
	while (fscanf(rFile, "%s", savstr) != EOF) {
		string = savstr;
//		temp = temp + 1;
		//if (i <= 0) *fl = 1;
		for (j = 0; j < dxconjlen; j++)
			dxconj[j][0] = '\0';
		woclause[0] = '\0';
		stagstr[0] = '\0';
		gender = ' ';
		storechar = '+';
		i = 0;
		while ((storechar == '+') && (i < dxconjlen))
		{
			dxconj[i][0] = (string++)[0];
			if (dxconj[i][0] == 'S')
			{
				for (j = 1; j <= reflen; j++)
					dxconj[i][j] = (string++)[0];
				storechar = (string++)[0];
				if (storechar == '-')
				{
					dxconj[i][reflen + 1] = storechar;
					for (j = 0; j <= reflen; j++)
						dxconj[i][reflen + j + 2]
						= (string++)[0];
					dxconj[i][stranlen] = '\0';
					storechar = (string++)[0];
				}
				else dxconj[i][reflen + 1] = '\0';
			}
			else
			{
				for (j = 1; j < dxlen; j++)
					dxconj[i][j] = (string++)[0];
				storechar = (string++)[0];
				if (storechar == '-')
				{
					dxconj[i][dxlen] = storechar;
					for (j = 0; j < dxlen; j++)
						dxconj[i][dxlen + j + 1]
						= (string++)[0];
					dxconj[i][rangelen] = '\0';
					storechar = (string++)[0];
				}
				else dxconj[i][dxlen] = '\0';
			}
			i++;
		}
		while (storechar != '\0')
		{
			switch (storechar)
			{
			case '"':
				for (i = 0; i < stlen; i++)
				{
					storechar = (string++)[0];
					if (storechar == '"')
					{
						stagstr[i] = '\0';
						i = stlen;
					}
					else stagstr[i] = storechar;
				}
				break;
			case 'M': case 'F':
				gender = storechar;
				break;
			case 'w':
				string++; string++; string++;
				for (i = 0; i < wolen; i++)
				{
					storechar = (string++)[0];
					if (storechar == ')')
					{
						woclause[i] = '\0';
						i = wolen;
					}
					else woclause[i] = storechar;
				}
				break;
			default:
				printf("Error: ill-formed rule in rule file\n");
				printf("Rule was: *%s*\n", savstr);
				printf("Char was: *%c*\n", storechar);
				exit(1);
			} // end of switch on storechar
			storechar = (string++)[0];
		}
		if (!(*fl)) fructify(0, NULL);
	}
	*fl = 1;
} // end of RULE::RULE


void RULE::fructify(int i, LINK* currlink)
{
	STAGE result = stfmt(stagstr);
	int d;
	DXRANGE dxr;
	STAGE st;
	LINK* nextlink;
	char* ptr;
	int bot, top;
	if (i<dxconjlen)
	{
		switch (dxconj[i][0])
		{
		case '\0':
			fructify(i + 1, currlink);
			break;
		case 'S': //stage reference
			st.dxcat = result.dxcat;
			switch (dxconj[i][reflen + 1])
			{
			case '\0':
				ptr = &dxconj[i][1];
				bot = atoi(ptr);
				top = bot;
				break;
			case '-':
				ptr = &dxconj[i][reflen + 3];
				top = atoi(ptr);
				dxconj[i][reflen + 1] = '\0';
				ptr = &dxconj[i][1];
				bot = atoi(ptr);
				break;
			default:
				printf("Error: bad delimiter in stage range\n");
				exit(1);
			}
			for (st.stage = bot; st.stage <= top; (st.stage)++)
				if (grove[st.dxcat][st.stage] != NULL)
					fructify(i + 1, grove[st.dxcat][st.stage]);
			break;
		default:
			if (currlink == NULL) currlink =
				orchard[bin(dxconj[i])];
			switch (dxconj[i][dxlen])
			{
			case '\0':
				d = dxint(dxconj[i]);
				nextlink = (LINK*)new DXLINK(d);
				break;
			case '-':
				ptr = dxconj[i];
				dxr.lo = dxint(ptr);
				ptr = &dxconj[i][dxlen + 1];
				dxr.hi = dxint(ptr);
				nextlink = (LINK*)new DXRLINK(dxr);
				break;
			default:
				printf("Error: bad delimiter in dx conjunct\n");
				exit(1);
			}
			currlink = currlink->push(nextlink);
			fructify(i + 1, currlink);
		} // end of switch on dxconj[i][0]
	} // end of if i<dxconjlen
	else
	{
		if (gender != ' ')
		{
			nextlink = (LINK*)new XLINK(gender);
			currlink = currlink->push(nextlink);
		}
		if (woclause[0] != '\0')
		{
			nextlink = (LINK*)new WLINK(woclause);
			currlink = currlink->push(nextlink);
		}
		if (grove[result.dxcat][result.stage] == NULL)
			grove[result.dxcat][result.stage] =
			(LINK*)new STLINK(result);
		currlink = currlink->push(grove[result.dxcat][result.stage]);
	} // end of if not i<dxconjlen
} // end of RULE::fructify


// global utility functions

STAGE stfmt(char* stagstr)
{
	char string[stlen];
	int i;
	STAGE result;
	for (i = 0; i<4; i++)
		string[i] = stagstr[i];
	string[4] = '\0';
	result.dxcat = atoi(string);
	string[0] = stagstr[5];
	string[1] = stagstr[7];
	string[2] = '\0';
	result.stage = atoi(string);
	return result;
}

char sexfmt(char s)
{
	switch (s)
	{
	case '1':
		return 'M'; break;
	case '2':
		return 'F'; break;
	default:
		return ' '; break;
	}
}

int ctoi(char c)
{
	switch (c)
	{
	case 'E':
		return 10;
	case 'V':
		return 11;
	case 'P':
		return 12;
	default: // number
		return (((int)c) - ((int)'0'));
	}
}

int dxint(char* string)
{
	int i;
	int code = 0;
	int place = 1;
	for (i = dxlen - 1; i>0; i--)
	{
		code += ((int)(string[i]) - 48) * place;
		place *= 10;
	}
	code += place * ctoi(string[0]);
	return code;
}

inline int bin(char* d)
{
	return (int)(dxint(d) / 100);
}

inline int bin(int d)
{
	return (int)(d / 100);
}


// global control functions

void plant(char* refdir)
{

	errno_t err;

	RULE* ru;
	int i, j, doneflag;
	char* rfilename = (char*)malloc(80 * sizeof(char));
	const char* rfn = "\\rules.txt";

	i = -1;
	while (refdir[++i] != '\0')
	{
		rfilename[i] = refdir[i];
	}
	j = 0;

	do
	{
		rfilename[i + j] = rfn[j];
	} while (rfn[j++] != '\0');

	// rulfile = fopen(rfilename, "rt");
	//rfilename = "c:\\users\\ctorres\\rules.txt";
	err = fopen_s(&rFile, rfilename, "rt");
	// if (rulfile == NULL)
	if (err != 0)
	{
		printf("failed to open rule file\n");
		exit(1);
	}
	doneflag = 0;
	while (!(doneflag))
	{
		ru = new RULE(&doneflag);
		delete ru;
	}
	if (rFile != NULL) fclose(rFile);
}


void harvest(char* workdir)
{
	errno_t errPFile, errOFile, errVFile;

	int id = 1;
	int doneflag = 0;
	PATIENT* pat;
	char *pfilename, *ofilename, *vfilename;
	int i, j;

	pfilename = (char*)malloc(80 * sizeof(char));
	ofilename = (char*)malloc(80 * sizeof(char));
	vfilename = (char*)malloc(80 * sizeof(char));

	const char* pfn = "\\patients.txt";
	const char* ofn = "\\staged.txt";
	const char* vfn = "\\triples.txt";

	i = -1;
	while (workdir[++i] != '\0')
	{
		pfilename[i] = workdir[i];
		ofilename[i] = workdir[i];
		vfilename[i] = workdir[i];
	}

	j = 0;
	do
	{
		pfilename[i + j] = pfn[j];
	} while (pfn[j++] != '\0');
	
	j = 0;
	do
	{
		ofilename[i + j] = ofn[j];
	} while (ofn[j++] != '\0');
	
	j = 0;
	do
	{
		vfilename[i + j] = vfn[j];
	} while (vfn[j++] != '\0');

	//patfile = fopen(pfilename, "rt");
	errPFile = fopen_s(&patfile, pfilename, "rt");
	//if (patfile == NULL)
	if (errPFile != 0)
	{
		printf("failed to open patient file %s\n", pfilename);
		exit(1);
	}


	//outfile = fopen(ofilename, "wt");
	errOFile = fopen_s(&outfile, ofilename, "wt");
	//if (outfile == NULL)
	if (errOFile != 0)
	{
		printf("failed to open output file %s\n", ofilename);
		exit(1);
	}


	if (verbose)
	{
		//verbosefile = fopen(vfilename, "wt");
		errVFile = fopen_s(&verbosefile, vfilename, "wt");
		//if (verbosefile == NULL)
		if (errVFile != 0)
		{
			printf("failed to open triple file %s\n", vfilename);
			exit(1);
		}
	}

	free(pfilename);
	free(ofilename);
	free(vfilename);

	//pat = new PATIENT(id++, &doneflag);

	while (doneflag == 0)
	{
		pat = new PATIENT(id++, &doneflag);
		pat->propagate();
		pat->output();
		delete pat;
		//pat = new PATIENT(id++, &doneflag);
	}


	if (patfile != NULL) fclose(patfile);
	// fclose(stream2);
	if (outfile != NULL) fclose(outfile);
	// fclose(streamOFile);
	if (verbosefile != NULL) fclose(verbosefile);
	//if (verbose) fclose(streamVFile);
}

//main(int argc, char** argv)
int  main(int argc, char** argv)
{
	int i, j;
	if (argc < 3)
	{
		printf("Must specify reference and work directories/n");
		exit(1);
	}
	verbose = 0;
	if (argc > 3)
		if (argv[3][0] == 'v') verbose = 1;
	for (i = 0; i<osize; i++)
		orchard[i] = new LINK();
	for (i = 0; i<lastdxc; i++)
		for (j = 0; j<laststag; j++)
			grove[i][j] = NULL;
	plant(argv[1]);
	harvest(argv[2]);
}

Open in new window

0
 
LVL 86

Expert Comment

by:jkr
Comment Utility
Well, first of all, I'd say ignore it, it's a bogus message. You are initializin 'head' in the PATIENT constructor. But you might want to try to provide a default constructor that does that as well (and I guess that's why PREfast complains), e.g.

class PATIENT
{
private:
	int id;                  // obs number from input SAS dataset
	char gender;             // '2' is female, '1' is male, ' ' missing
	int dxs[maxdxs];         // array of diagnoses
	int ndxs;                // number of diagnoses which patient has
	TRIPLE* head;            // head of linked list of triples
	int inclause(int, char*);// subfunction of without
	int in(int, char*);      // subfunction of inclause
public:
	PATIENT();        // default constructor <-----!
	PATIENT(int, int*);        // constructor
	~PATIENT();                // destructor
	int match(int, int*);      // check if patient has a diagnosis
	int matchr(DXRANGE, int*); // same, but for diagnosis range
	int without(char*);        // check if patient has none of the diags
	inline int sex(char g);    // check if patient is of this sex
	void attain(TRIPLE*);      // accept a stage which was reached
	void propagate();          // search through rules for matches
	void output();             // write attained triples to file
};

// ...

PATIENT::PATIENT() // default ctor <-----!
{

	ndxs = 0;
	head = NULL;
	id = 0;
        gender = ' ';
}

Open in new window

0
 

Author Comment

by:CarmenMTorres
Comment Utility
I tried what you recommended but I still get the message.  

Since the issue pertains to memory, by not having it initialized, wouldn't that pose a serious problem down the road?  I was always told that unresolved issues with memory will eventually surface even though the program may have been working for a while.
0
 
LVL 86

Accepted Solution

by:
jkr earned 500 total points
Comment Utility
Sorry, was barking up the wrong tre, 'TRIPLE' needs that initialization:

struct TRIPLE {
       TRIPLE() : p(0), next(NULL) {};
       STAGE s;
       int p;        // pflag
      TRIPLE* next;
};

Open in new window


But again, that's snake oil. That tool performs a static analysis, and you are dealing with dynamic memory here.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now