Skip to content

Commit 08fbf69

Browse files
committed
Fixing bug when loading poorly formatted lattice vector block in OUTCAR files
1 parent ead4eba commit 08fbf69

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

src/data/structure_loader.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,19 @@ inline bool parse_six_columns(const std::string& line,
9595
double& c3,
9696
double& c4,
9797
double& c5,
98-
double& c6) {
99-
return std::sscanf(line.c_str(), " %lf %lf %lf %lf %lf %lf", &c1, &c2, &c3, &c4, &c5, &c6) == 6;
98+
double& c6)
99+
{
100+
const char* p = line.c_str();
101+
char* end;
102+
103+
c1 = std::strtod(p, &end); if (p == end) return false; p = end;
104+
c2 = std::strtod(p, &end); if (p == end) return false; p = end;
105+
c3 = std::strtod(p, &end); if (p == end) return false; p = end;
106+
c4 = std::strtod(p, &end); if (p == end) return false; p = end;
107+
c5 = std::strtod(p, &end); if (p == end) return false; p = end;
108+
c6 = std::strtod(p, &end); if (p == end) return false;
109+
110+
return true;
100111
}
101112

102113
}

0 commit comments

Comments
 (0)