[SOLVED] Stack around variable is corrupted - sscanf()
AFter some performance analyitics i foudn that we spend most of our time when loading files in this function. I tried to change from using stringstream to using scanf() instead, hoping it will yield some better performance characteristics.
Of course sscanf is less secure then using a stringstream, and therefore I get run-time errors right of the bat.
auto Parser::nextKeyVertex() -> KeyVertex {
auto[key, valueString, err] = nextKeyString();
if (err == PARSE_ERROR)
return KeyVertex{"", {}, PARSE_ERROR};
Vertex vert{};
float u, v;
float nx, ny, nz;
// 1.351676 0.301667 0.100000 0.000 0.000 1.000 0.000 0.000 255 255 255 255
auto changecount = sscanf(valueString.data(), "%f %f %f %f %f %f %f %f %u %u %u %u",
&vert.x, &vert.y, &vert.z, &nx, &ny, &nz, &u, &v, &vert.r, &vert.g, &vert.b, &vert.a);
if (changecount != 12) {
return KeyVertex{ "",{}, PARSE_ERROR };
}
vert.n = Util::packNormal(nx, ny, nz);
vert.uv = Util::packUV(u, v);
return KeyVertex{ key, vert, PARSE_SUCCESS };
}
Edited by Jonas Johan Solsvik