better error reporting

This commit is contained in:
Francesco Cozzuto
2022-01-14 19:21:26 +01:00
parent 242398584c
commit c391de463c
2 changed files with 68 additions and 21 deletions
+30 -15
View File
@@ -116,9 +116,13 @@ static int scanValue(FILE *fp, char *buffer, int max_length, char first, char *f
do
{
if(n == max_length)
// ERROR: Internal buffer is too small to hold
// the representation of this item.
return 0;
{
// ERROR: Internal buffer is too small to hold
// the representation of this item.
*error = "Internal buffer is too small to hold "
"the representation of a numeric value";
return 0;
}
buffer[n++] = c;
@@ -136,27 +140,38 @@ static int scanValue(FILE *fp, char *buffer, int max_length, char first, char *f
if(dot)
{
if(n == max_length)
// ERROR: Internal buffer is too small to hold
// the representation of this item.
// (The dot doesn't fit.)
return 0;
{
// ERROR: Internal buffer is too small to hold
// the representation of this item.
// (The dot doesn't fit.)
*error = "Internal buffer is too small to hold "
"the representation of a numeric value";
return 0;
}
buffer[n++] = '.';
c = getc(fp);
if(!isdigit(c))
// ERROR: Got something other than a
// digit after the dot.
return 0;
{
// ERROR: Got something other than a
// digit after the dot.
*error = "Got something other than a digit after the dot.";
return 0;
}
do
{
if(n == max_length)
// ERROR: Internal buffer is too small
// to hold the representation of
// this item.
return 0;
{
// ERROR: Internal buffer is too small
// to hold the representation of
// this item.
*error = "Internal buffer is too small to hold "
"the representation of a numeric value";
return 0;
}
buffer[n++] = c;