SScanf cannot read character classes

I have the following (sample) binary template of nested structures:

typedef struct
{
  int a;
  int b;
  int c;
} Vec <read=VecRead, write=VecWrite>;
string VecRead(Vec& v)
{
  return Str("(%d, %d, %d)", v.a, v.b, v.c);
}
void VecWrite(Vec& v, string s)
{
  SScanf(s, "(%d, %d, %d)", v.a, v.b, v.c);
}

typedef struct
{
  Vec x;
  Vec y;
} Mat <read=MatRead, write=MatWrite>;
string MatRead(Mat& m)
{
  return Str("(%s, %s)", VecRead(m.x), VecRead(m.y));
}
void MatWrite(Mat& m, string s)
{
  string x, y;
  SScanf(s, "(%[^)]), %[^)]))", x, y); // ERROR (s. below)
  VecWrite(m.x, x);
  VecWrite(m.y, y);
}

// content of attached test file:
BigEndian();
Mat mat;

Mat includes two instances of Vec, and in the write function, I try to reuse the functionality of Vec just as I did in the read function.

However, it seems SScanf does not understand character classes to extract the Vec substrings %[^)] (read everything up to the next )). When trying to edit the value in 010, it will only print *ERROR: Argument 2 was an incompatible type for function ‘SScanf’.

Are character classes not supported in 010 or am I doing something wrong here?

(I’ve actually found the same usage in an older script that I should’ve tested thoroughly, so I wonder if this actually worked once and only broke in the latest v16.0.)

Attached a sample binary file together with the binary template for you to test:

sample.zip (577 Bytes)

SScanf currently does not currently understand character classes. Old versions of 010 Editor did not do type checking for SScanf so it was possible to crash the whole program but character classes probably would work. Newer versions do type checking but they are not detecting the character classes correctly. We’ll see if we can get this fixed in our next v17 but for now you’ll have to do a workaround and check for the bracket locations yourself. Let us know if you need help getting this setup.

Graeme
SweetScape Software

1 Like

Thank you for confirming that I was not hallucinating that this did work a while ago :slight_smile: For now I just remove the write methods as users can always expand and edit the inner contents. If this will get fixed I’ll put them back in place.

Thanks!