better error reporting
This commit is contained in:
@@ -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.
|
||||
*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.)
|
||||
*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.
|
||||
*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.
|
||||
*error = "Internal buffer is too small to hold "
|
||||
"the representation of a numeric value";
|
||||
return 0;
|
||||
}
|
||||
|
||||
buffer[n++] = c;
|
||||
|
||||
|
||||
@@ -15,12 +15,44 @@ struct {
|
||||
double *matrix;
|
||||
int w, h;
|
||||
} load_tests[] = {
|
||||
{ .src = "", .matrix = NULL },
|
||||
{ .src = " [] ", .matrix = NULL },
|
||||
{ .src = " [1] ", .matrix = (double[]) {1}, .w = 1, .h = 1 },
|
||||
{ .src = "[1 2 3]", .matrix = (double[]) {1, 2, 3}, .w = 3, .h = 1 },
|
||||
{ .src = "[1, 2, 3]", .matrix = (double[]) {1, 2, 3}, .w = 1, .h = 3 },
|
||||
{ .src = "[1 2 3, 4 5 6, 7 8 9]", .matrix = (double[]) {1, 2, 3, 4, 5, 6, 7, 8, 9}, .w = 3, .h = 3 },
|
||||
{
|
||||
.src = "",
|
||||
.matrix = NULL
|
||||
},
|
||||
{
|
||||
.src = " [] ",
|
||||
.matrix = NULL
|
||||
},
|
||||
{
|
||||
.src = " [1] ",
|
||||
.matrix = (double[]) {1},
|
||||
.w = 1,
|
||||
.h = 1
|
||||
},
|
||||
{
|
||||
.src = "[1 2 3]",
|
||||
.matrix = (double[]) {1, 2, 3},
|
||||
.w = 3,
|
||||
.h = 1
|
||||
},
|
||||
{
|
||||
.src = "[1, 2, 3]",
|
||||
.matrix = (double[]) {1, 2, 3},
|
||||
.w = 1,
|
||||
.h = 3
|
||||
},
|
||||
{
|
||||
.src = "[1 2 3, 4 5 6, 7 8 9]",
|
||||
.matrix = (double[]) {1, 2, 3, 4, 5, 6, 7, 8, 9},
|
||||
.w = 3,
|
||||
.h = 3
|
||||
},
|
||||
{
|
||||
.src = "[1.0 2.0 3.0, 4.7 5.0 6.0, 7.0 8.0 9.5]",
|
||||
.matrix = (double[]) {1, 2, 3, 4.7, 5, 6, 7, 8, 9.5},
|
||||
.w = 3,
|
||||
.h = 3
|
||||
},
|
||||
};
|
||||
|
||||
int main()
|
||||
|
||||
Reference in New Issue
Block a user