P
pereges
Below , I have just posted some code. Can some one please tell me if
I'm going wrong somewhere with size_t variables ? I noticed that if I
try to check if size_t variable < 0 , then compiler gives a warning.
But there have been situations where my program failed because the
variable assume garbage values.
int parse_sizes(FILE *fp)
{
size_t nvert, ntri;
int rc = 0;
if (fscanf(fp, "%lu%*lu%lu", &nvert, &ntri) != 2)
{
error_report("Error while parsing the file");
rc = 1;
return (rc);
}
if (nvert < MIN_VERTEX_LIMIT || nvert > MAX_VERTEX_LIMIT)
{
error_report("Number of vertices out of range");
rc = 1;
return (rc);
}
if (ntri < MIN_TRIANGLE_LIMIT || ntri > MAX_TRIANGLE_LIMIT)
{
error_report("Number of triangles out of range");
rc = 1;
return (rc);
}
m_ptr->ntri = ntri;
m_ptr->nvert = nvert;
if (m_ptr->ntri != ntri || m_ptr->nvert != nvert)
{
error_report("Number of vertices out of range");
rc = 1;
return (rc);
}
return (rc);
}
I'm going wrong somewhere with size_t variables ? I noticed that if I
try to check if size_t variable < 0 , then compiler gives a warning.
But there have been situations where my program failed because the
variable assume garbage values.
int parse_sizes(FILE *fp)
{
size_t nvert, ntri;
int rc = 0;
if (fscanf(fp, "%lu%*lu%lu", &nvert, &ntri) != 2)
{
error_report("Error while parsing the file");
rc = 1;
return (rc);
}
if (nvert < MIN_VERTEX_LIMIT || nvert > MAX_VERTEX_LIMIT)
{
error_report("Number of vertices out of range");
rc = 1;
return (rc);
}
if (ntri < MIN_TRIANGLE_LIMIT || ntri > MAX_TRIANGLE_LIMIT)
{
error_report("Number of triangles out of range");
rc = 1;
return (rc);
}
m_ptr->ntri = ntri;
m_ptr->nvert = nvert;
if (m_ptr->ntri != ntri || m_ptr->nvert != nvert)
{
error_report("Number of vertices out of range");
rc = 1;
return (rc);
}
return (rc);
}