paulfrance
Programmer
Does anyone know what is happening here? The code sample below compiles and runs but Codeguard says the sscanf is causing an error of type 'access in invalid stack'. But, if I step through the code past the ::sscanf, the values all get scanned correctly and count=4 which it should do. Another thing is, I'm sure that when I wrote this code it worked fine for a couple of days and then broke but maybe I changed something and forgot about it. I think the problem lies with the format values that are not assigned "%*1c%*3d" and if I remove them from the format string and also from my original string it works OK but I can't see why. I'm using Borland C++ v5.02 under Win200.
Here's the code:-
bool SP3::MeasurementSet::Record::Read(const Line &line)
{
double X = 0.;
double Y = 0.;
double Z = 0.;
double clock = 0.;
char *testLine = "P 1 135.855261 -26246.362382 -3758.216999 161.418381 ";
//testLine used for this example, generally line is passed in
int count = ::sscanf(testLine, "%*1c%*3d%14lf%14lf%14lf%14lf", &X, &Y, &Z, &clock);
if (count != 4)
return false;
return Set(X, Y, Z, clock);
}
Thanks for your time and trouble,
Paul.
Here's the code:-
bool SP3::MeasurementSet::Record::Read(const Line &line)
{
double X = 0.;
double Y = 0.;
double Z = 0.;
double clock = 0.;
char *testLine = "P 1 135.855261 -26246.362382 -3758.216999 161.418381 ";
//testLine used for this example, generally line is passed in
int count = ::sscanf(testLine, "%*1c%*3d%14lf%14lf%14lf%14lf", &X, &Y, &Z, &clock);
if (count != 4)
return false;
return Set(X, Y, Z, clock);
}
Thanks for your time and trouble,
Paul.